@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()); }
public ServletLogger( final String name, final Queue<SubstituteLoggingEvent> eventQueue, final boolean createdPostInitialization, final @NotNull ServletContext context) { super(name, eventQueue, createdPostInitialization); servletContext = context; }
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"); }
@Override public void processElement(DoFn<T, Void>.ProcessContext c) throws Exception { SubstituteLoggingEvent event = new SubstituteLoggingEvent(); event.setMessage(c.element().toString()); event.setLevel(this.level); logger.log(event); }