KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > util > LoggingBrokerPlugin


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.broker.util;
19
20 import org.apache.activemq.broker.BrokerPluginSupport;
21 import org.apache.activemq.broker.ConnectionContext;
22 import org.apache.activemq.broker.ConsumerBrokerExchange;
23 import org.apache.activemq.broker.ProducerBrokerExchange;
24 import org.apache.activemq.command.Message;
25 import org.apache.activemq.command.MessageAck;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * A simple Broker interceptor which allows you to enable/disable logging.
31  *
32  * @org.apache.xbean.XBean
33  *
34  * @version $Revision: 514131 $
35  */

36 public class LoggingBrokerPlugin extends BrokerPluginSupport {
37
38     private Log log = LogFactory.getLog(LoggingBrokerPlugin.class);
39     private Log sendLog = LogFactory.getLog(LoggingBrokerPlugin.class.getName()+".Send");
40     private Log ackLog = LogFactory.getLog(LoggingBrokerPlugin.class.getName()+".Ack");
41
42     public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception JavaDoc {
43         if (sendLog.isInfoEnabled()) {
44             sendLog.info("Sending: " + messageSend);
45         }
46         super.send(producerExchange, messageSend);
47     }
48
49     public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception JavaDoc {
50         if (ackLog.isInfoEnabled()) {
51             ackLog.info("Acknowledge: " + ack);
52         }
53         super.acknowledge(consumerExchange, ack);
54     }
55
56     // Properties
57
// -------------------------------------------------------------------------
58
public Log getAckLog() {
59         return ackLog;
60     }
61
62     public void setAckLog(Log ackLog) {
63         this.ackLog = ackLog;
64     }
65
66     public Log getLog() {
67         return log;
68     }
69
70     public void setLog(Log log) {
71         this.log = log;
72     }
73
74     public Log getSendLog() {
75         return sendLog;
76     }
77
78     public void setSendLog(Log sendLog) {
79         this.sendLog = sendLog;
80     }
81
82 }
83
Popular Tags