Thanks,
I'm building an appender for log4j that send the log events to JConsole.
Do you know what's wrong here, I'm not receiving any notifications:
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import org.apache.log4j.spi.LoggingEvent;
import javax.management.NotificationBroadcasterSupport;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.Filter;
public class JMXLogAppender extends NotificationBroadcasterSupport implements JMXLogAppenderMBean, Appender
{
static private final String LOG_EVENT_TYPE = "LOG_EVENT";
static private final String LOG_MBEAN_DESCR = "LogAppender MBean";
private String appenderName_;
private Layout layout_;
private long sequence_ = 0;
public JMXLogAppender()
{
}
public MBeanNotificationInfo[] getNotificationInfo()
{
String[] types = new String[] { LOG_EVENT_TYPE };
String name = Notification.class.getName();
MBeanNotificationInfo info = new MBeanNotificationInfo( types, name, LOG_MBEAN_DESCR );
return new MBeanNotificationInfo[] { info };
}
public int getValue()
{
return 0;
}
public void setName( String name )
{
appenderName_ = name;
}
public String getName()
{
return appenderName_;
}
public void addFilter(Filter filter)
{
return;
}
public Filter getFilter()
{
return null;
}
public void clearFilters()
{
}
public void setErrorHandler( ErrorHandler errorHandler )
{
}
public ErrorHandler getErrorHandler()
{
return null;
}
public void setLayout(Layout layout)
{
layout_ = layout;
}
public Layout getLayout()
{
return layout_;
}
public void doAppend( LoggingEvent event )
{
synchronized(this)
{
sequence_++ ;
}
String message = event.getRenderedMessage();
Notification notif = new Notification( LOG_EVENT_TYPE, this, sequence_ );// , event.timeStamp, message );
sendNotification( notif );
}
public boolean requiresLayout()
{
return true;
}
public void close()
{
}
}