KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > logging > JMXAppender


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.logging;
5
6 import org.apache.log4j.AppenderSkeleton;
7 import org.apache.log4j.spi.LoggingEvent;
8
9 import com.tc.exception.TCRuntimeException;
10 import com.tc.management.beans.logging.TCLoggingBroadcaster;
11 import com.tc.management.beans.logging.TCLoggingBroadcasterMBean;
12
13 import javax.management.NotCompliantMBeanException JavaDoc;
14
15 /**
16  * Special Appender that notifies JMX listeners on LoggingEvents.
17  *
18  * @see org.apache.log4j.RollingFileAppender
19  * @see TCLoggingBroadcasterMBean
20  * @author gkeim
21  */

22 public class JMXAppender extends AppenderSkeleton {
23
24   private final TCLoggingBroadcaster broadcastingBean;
25
26   public JMXAppender() {
27     try {
28       broadcastingBean = new TCLoggingBroadcaster();
29     } catch (NotCompliantMBeanException JavaDoc ncmbe) {
30       throw new TCRuntimeException("Unable to construct the broadcasting MBean: this is a programming error in "
31                                    + TCLoggingBroadcaster.class.getName(), ncmbe);
32     }
33   }
34
35   public final TCLoggingBroadcasterMBean getMBean() {
36     return broadcastingBean;
37   }
38
39   protected void append(final LoggingEvent event) {
40     broadcastingBean.broadcastLogEvent(getLayout().format(event));
41   }
42
43   public boolean requiresLayout() {
44     return false;
45   }
46
47   public void close() {
48     // Do nothing
49
}
50
51 }
52
Popular Tags