@Test public void appenderTest() { final CountingAppender appender = new CountingAppender(); final StringAppender stringAppender = new StringAppender(); log4jLogger.addAppender(appender); log4jLogger.addAppender(stringAppender); log4jLogger.info(MESSAGE); org.jboss.logging.Logger.getLogger(getClass()).info(JBL_MESSAGE); java.util.logging.Logger.getLogger(getClass().getName()).info(JUL_MESSAGE); final String stringFormat = "This is a %s format test."; org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "string"); final String msgFormat = "This is a {} format test."; org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "message"); assertEquals(5, appender.counter); assertEquals(5, stringAppender.messages.size()); assertEquals(MESSAGE, stringAppender.messages.get(0)); assertEquals(JBL_MESSAGE, stringAppender.messages.get(1)); assertEquals(JUL_MESSAGE, stringAppender.messages.get(2)); assertFalse(stringFormat.equals(stringAppender.messages.get(3))); assertFalse(msgFormat.equals(stringAppender.messages.get(4))); }
@Test public void rootAppenderTest() { final CountingAppender appender = new CountingAppender(); final StringAppender stringAppender = new StringAppender(); root.addAppender(appender); root.addAppender(stringAppender); root.info(ROOT_LOGGER_MSG); final String msg = JBL_MESSAGE + " root logger"; org.jboss.logmanager.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg); org.jboss.logging.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg); assertEquals(3, appender.counter); assertEquals(3, stringAppender.messages.size()); assertEquals(ROOT_LOGGER_MSG, stringAppender.messages.get(0)); assertEquals(msg, stringAppender.messages.get(1)); assertEquals(msg, stringAppender.messages.get(2)); }
@Test public void duplicateAppenderTest() { final CountingAppender appender = new CountingAppender(); final StringAppender stringAppender = new StringAppender(); root.addAppender(appender); root.addAppender(stringAppender); root.info(ROOT_LOGGER_MSG); log4jLogger.addAppender(stringAppender); log4jLogger.info(MESSAGE); org.jboss.logging.Logger.getLogger(getClass()).info(JBL_MESSAGE); assertEquals(3, appender.counter); assertEquals(5, stringAppender.messages.size()); assertEquals(ROOT_LOGGER_MSG, stringAppender.messages.get(0)); assertEquals(MESSAGE, stringAppender.messages.get(1)); assertEquals(MESSAGE, stringAppender.messages.get(2)); assertEquals(JBL_MESSAGE, stringAppender.messages.get(3)); assertEquals(JBL_MESSAGE, stringAppender.messages.get(4)); }