01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.logging;
05:
06: import org.apache.log4j.AppenderSkeleton;
07: import org.apache.log4j.spi.LoggingEvent;
08:
09: 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;
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 ncmbe) {
30: throw new TCRuntimeException(
31: "Unable to construct the broadcasting MBean: this is a programming error in "
32: + TCLoggingBroadcaster.class.getName(),
33: ncmbe);
34: }
35: }
36:
37: public final TCLoggingBroadcasterMBean getMBean() {
38: return broadcastingBean;
39: }
40:
41: protected void append(final LoggingEvent event) {
42: broadcastingBean.broadcastLogEvent(getLayout().format(event));
43: }
44:
45: public boolean requiresLayout() {
46: return false;
47: }
48:
49: public void close() {
50: // Do nothing
51: }
52:
53: }
|