private static final void fixSubstitutedLoggers() { List loggers = TEMP_FACTORY.getLoggers(); if(!loggers.isEmpty()) { Util.report("The following set of substitute loggers may have been accessed"); Util.report("during the initialization phase. Logging calls during this"); Util.report("phase were not honored. However, subsequent logging calls to these"); Util.report("loggers will work as normally expected."); Util.report("See also http://www.slf4j.org/codes.html#substituteLogger"); Iterator i$ = loggers.iterator(); while(i$.hasNext()) { SubstituteLogger subLogger = (SubstituteLogger)i$.next(); subLogger.setDelegate(getKonkerLogger(subLogger.getName())); Util.report(subLogger.getName()); } TEMP_FACTORY.clear(); } }
private final static void fixSubstitutedLoggers() { List<SubstituteLogger> loggers = TEMP_FACTORY.getLoggers(); if (loggers.isEmpty()) { return; } Util.report("The following set of substitute loggers may have been accessed"); Util.report("during the initialization phase. Logging calls during this"); Util.report("phase were not honored. However, subsequent logging calls to these"); Util.report("loggers will work as normally expected."); Util.report("See also " + SUBSTITUTE_LOGGER_URL); for (SubstituteLogger subLogger : loggers) { subLogger.setDelegate(getLogger(subLogger.getName())); Util.report(subLogger.getName()); } TEMP_FACTORY.clear(); }
@Test public void log_errors() { final CommandEnvelope commandEnvelope = givenCommandEnvelope(); // Since we're in the tests mode `Environment` returns `SubstituteLogger` instance. final SubstituteLogger log = (SubstituteLogger) handler.log(); // Restrict the queue size only to the number of calls we want to make. final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(1); log.setDelegate(new EventRecodingLogger(log, queue)); SubstituteLoggingEvent loggingEvent; final RuntimeException exception = new RuntimeException("log_errors"); handler.onError(commandEnvelope, exception); loggingEvent = queue.poll(); assertEquals(Level.ERROR, loggingEvent.getLevel()); assertEquals(commandEnvelope, handler.getLastErrorEnvelope()); assertEquals(exception, handler.getLastException()); }
private void assertAtLevel(Level level) { final LoggingObserver<Object> observer = getObserver(level); assertNotNull(observer); // Since we're in the tests mode `Environment` returns `SubstituteLogger` instance. final SubstituteLogger log = (SubstituteLogger) observer.log(); // Restrict the queue size only to the number of calls we want to make. final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(3); log.setDelegate(new EventRecodingLogger(log, queue)); SubstituteLoggingEvent loggingEvent; final String value = newUuid(); observer.onNext(value); loggingEvent = queue.poll(); assertNotNull(loggingEvent); assertLogLevel(loggingEvent, level); assertContains(loggingEvent, value); assertContains(loggingEvent, "onNext"); final Timestamp currentTime = Time.getCurrentTime(); final String timeStr = Timestamps.toString(currentTime); observer.onNext(currentTime); loggingEvent = queue.poll(); assertNotNull(loggingEvent); assertLogLevel(loggingEvent, level); assertContains(loggingEvent, timeStr); observer.onCompleted(); loggingEvent = queue.poll(); assertNotNull(loggingEvent); assertLogLevel(loggingEvent, level); assertContains(loggingEvent, "onCompleted"); }