JmxAppender extends AppenderSkeleton { public JmxAppender() { this(ManagementFactory.getPlatformMBeanServer()); } JmxAppender();  JmxAppender(MBeanServer mbeanServer); void close(); boolean requiresLayout(); static final String JMX_OBJECT_DOMAIN; static final String JMX_OBJECT_TYPE; static final String JMX_OBJECT_NAME; }
@Test public void testJmxAppender() throws Exception { MBeanServerConnection mbserver = JMXConnectorFactory.connect(URL).getMBeanServerConnection(); ObjectName objectName = new ObjectName(JmxAppender.JMX_OBJECT_DOMAIN + ":type=" + JmxAppender.JMX_OBJECT_TYPE + ",name=" + JmxAppender.JMX_OBJECT_NAME); String level = null; MockAppender mockAppender = new MockAppender(); Logger.getRootLogger().addAppender(mockAppender); level = (String) mbserver.getAttribute(objectName, "Level"); assertEquals("INFO", level); log.info("info1"); log.debug("debug1"); mbserver.setAttribute(objectName, new Attribute("Level", "debug")); level = (String) mbserver.getAttribute(objectName, "Level"); assertEquals("DEBUG", level); log.info("info2"); log.debug("debug2"); List<LoggingEvent> logLines = mockAppender.getLogLines(); Iterator<LoggingEvent> logLineIterator = logLines.iterator(); assertEquals(3, logLines.size()); assertEquals("info1", logLineIterator.next().getMessage()); assertEquals("info2", logLineIterator.next().getMessage()); assertEquals("debug2", logLineIterator.next().getMessage()); }