@Before public void setUp() throws Exception { context = new LoggerContext(); context.setName("test"); context.start(); logger = context.getLogger(TurboFilteringInLoggerTest.class); }
@Test public void contextNameTest() { pl.setPattern("%contextName"); lc.setName("aValue"); pl.start(); String val = pl.doLayout(getEventObject()); assertEquals("aValue", val); }
@Test public void tException() throws InterruptedException { int port = RandomUtil.getRandomServerPort(); MockSyslogServer mockServer = new MockSyslogServer(21, port); mockServer.start(); // give MockSyslogServer head start Thread.sleep(100); LoggerContext lc = new LoggerContext(); lc.setName("test"); SyslogAppender sa = new SyslogAppender(); sa.setContext(lc); sa.setSyslogHost("localhost"); sa.setFacility("MAIL"); sa.setPort(port); sa.setSuffixPattern("[%thread] %logger %msg"); sa.start(); assertTrue(sa.isStarted()); String loggerName = this.getClass().getName(); Logger logger = lc.getLogger(loggerName); logger.addAppender(sa); String logMsg = "hello"; String exMsg = "just testing"; Exception ex = new Exception(exMsg); logger.debug(logMsg, ex); // StatusPrinter.print(lc.getStatusManager()); // wait max 2 seconds for mock server to finish. However, it should // much sooner than that. mockServer.join(8000); assertTrue(mockServer.isFinished()); // message + 20 lines of stacktrace assertEquals(21, mockServer.getMessageList().size()); // int i = 0; // for (String line: mockServer.msgList) { // System.out.println(i++ + ": " + line); // } String msg = mockServer.getMessageList().get(0); String expected = "<" + (SyslogConstants.LOG_MAIL + SyslogConstants.DEBUG_SEVERITY) + ">"; assertTrue(msg.startsWith(expected)); String expectedPrefix = "<\\d{2}>\\w{3} \\d{2} \\d{2}(:\\d{2}){2} [\\w.-]* "; String threadName = Thread.currentThread().getName(); String regex = expectedPrefix + "\\[" + threadName + "\\] " + loggerName + " " + logMsg; checkRegexMatch(msg, regex); }
// check for deadlocks @Test(timeout = 4000L) public void scan_LOGBACK_474() throws JoranException, IOException, InterruptedException { loggerContext.setName("scan_LOGBACK_474"); File file = new File(SCAN_LOGBACK_474_FILE_AS_STR); // StatusListenerConfigHelper.addOnConsoleListenerInstance(loggerContext, new // OnConsoleStatusListener()); configure(file); // ReconfigureOnChangeTask roct = waitForReconfigureOnChangeTaskToRun(); int expectedResets = 2; Harness harness = new Harness(expectedResets); RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(file, UpdateType.TOUCH); harness.execute(runnableArray); loggerContext.getStatusManager().add(new InfoStatus("end of execution ", this)); StatusPrinter.print(loggerContext); checkResetCount(expectedResets); }
@Test public void basic() throws InterruptedException { int port = RandomUtil.getRandomServerPort(); MockSyslogServer mockServer = new MockSyslogServer(1, port); mockServer.start(); // give MockSyslogServer head start Thread.sleep(100); LoggerContext lc = new LoggerContext(); lc.setName("test"); SyslogAppender sa = new SyslogAppender(); sa.setContext(lc); sa.setSyslogHost("localhost"); sa.setFacility("MAIL"); sa.setPort(port); sa.setSuffixPattern("[%thread] %logger %msg"); sa.start(); assertTrue(sa.isStarted()); String loggerName = this.getClass().getName(); Logger logger = lc.getLogger(loggerName); logger.addAppender(sa); String logMsg = "hello"; logger.debug(logMsg); // wait max 2 seconds for mock server to finish. However, it should // much sooner than that. mockServer.join(8000); assertTrue(mockServer.isFinished()); assertEquals(1, mockServer.getMessageList().size()); String msg = mockServer.getMessageList().get(0); String threadName = Thread.currentThread().getName(); String expected = "<" + (SyslogConstants.LOG_MAIL + SyslogConstants.DEBUG_SEVERITY) + ">"; assertTrue(msg.startsWith(expected)); String first = "<\\d{2}>\\w{3} \\d{2} \\d{2}(:\\d{2}){2} [\\w.-]* "; checkRegexMatch(msg, first + "\\[" + threadName + "\\] " + loggerName + " " + logMsg); }
@Before public void setUp() throws SQLException { dbAppenderHSQLTestFixture = new DBAppenderHSQLTestFixture(); dbAppenderHSQLTestFixture.setUp(); lc = new LoggerContext(); lc.setName("default"); logger = lc.getLogger("root"); appender = new DBAppender(); appender.setName("DB"); appender.setContext(lc); connectionSource = new DriverManagerConnectionSource(); connectionSource.setContext(lc); connectionSource.setDriverClass(DBAppenderHSQLTestFixture.HSQLDB_DRIVER_CLASS); connectionSource.setUrl(dbAppenderHSQLTestFixture.url); connectionSource.setUser(dbAppenderHSQLTestFixture.user); connectionSource.setPassword(dbAppenderHSQLTestFixture.password); connectionSource.start(); appender.setConnectionSource(connectionSource); appender.start(); }
@Before public void setUp() throws UnknownHostException { context.setName("c" + diff); context.putProperty("randomOutputDir", randomOutputDir); }
LoggerContextVO getRandomlyNamedLoggerContextVO() { LoggerContext lc = new LoggerContext(); lc.setName(getRandomJavaIdentifier()); return new LoggerContextVO(lc); }
@Before public void setUp() throws Exception { lc.setName("test"); sa.setContext(lc); }