The JMXNotificationAppender service
The JMXNotificationAppender is a simple log4j Appender and an MBean at
the same time, introduced in JBoss v4.0.3. The purpose of this service is to
tap into the log messages produced by the components that use log4j as a logging
implementation, and convert those messages to JMX notifications that can feed,
for example, the ActiveAlarmTable, or inform another mbean of yours of some
particular logging event taking place.
The appender/service can configured in conf/log4j.xml where it is
commented out, by default:
<!-- Emit events as JMX notifications --> <appender name="JMX" class="org.jboss.monitor.services.JMXNotificationAppender"> <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler> <param name="Threshold" value="WARN"/> <param name="ObjectName" value="jboss.system:service=Logging,type=JMXNotificationAppender"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p [%c] %m"/> </layout> </appender>
The properties that you can configure are:
Threshold, the log level over which the messages are to be converted,
the default is WARN.
to JMX notification.
ObjectName, the JMX ObjectName to use then registering to the local
MBeanServer used by jboss, defaults to jboss.system:service=Logging,type=JMXNotificationAppender.
NotificationType, the type to use in the produced notifications,
the default is jboss.alarm.logging.
Also, remember to add the JMX appender in the root category
... <root> <appender-ref ref="CONSOLE"></appender-ref> <appender-ref ref="FILE"></appender-ref> <appender-ref ref="JMX"></appender-ref> <!-- ADD HERE --> </root> ...
Normally, you'll want to convert to JMX notification only the most important
log events (level WARN and upper), but by modifying the log4j.xml configuration
you have precise control over what you map.
When you use the JMXNotificationAppender, be careful to avoid infinite recursion loops!
A-Logging-Source --> log4j --> JMXNotificationAppender --> WhatEverListener(s)
If WhatEverListener(s) starts having a problem and produces WARN/ERROR log4j messages,
those messages will be fed back to it, causing a possible infinite recursion
(even a possible core dump on some JVMs). To avoid this, disable the
JMXNotificationAppender (or else the JMX appender reference) for those
components/mbeans that process the JMXNotificationAppender notifications:
<category name="whatever-category" additivity="false"> <priority value="INFO"></priority> <appender-ref ref="CONSOLE"></appender-ref> <appender-ref ref="FILE"></appender-ref> </category>
The JMXNotificationAppender actually produces stateless
org.jboss.monitor.alarm.AlarmNotification notifications and performs a
simple log4j Level to org.jboss.monitor.alarm.Alarm severity mapping:
Level.WARN maps to Alarm.SEVERITY_WARNING
Level.ERROR maps to Alarm.SEVERITY_MAJOR;
Level.FATAL maps to Alarm.SEVERITY_CRITICAL
To feed the produced notifications to the ActiveAlarmTable, you must
subscribe for them, in the subscription specification of the alarm
table config:
... <subscription-list> ... <mbean name="jboss.system:service=Logging,type=JMXNotificationAppender"></mbean> ... </subscription-list> ...
Related:
Referenced by:
Comments