Logger { public JsonLogger error() { if (slf4jLogger.isErrorEnabled()) { StandardJsonLogger result = new StandardJsonLogger(this.slf4jLogger, this.formatter, this.gson, ERROR_LEVEL_NAME, this.slf4jLogger::error, this.slf4jLogger::error); this.configureLogger(result); return result; } return noopLogger; } Logger(org.slf4j.Logger slf4jLogger, FastDateFormat formatter); boolean isIncludeLoggerName(); void setIncludeLoggerName(boolean includeLoggerName); boolean isIncludeThreadName(); void setIncludeThreadName(boolean includeThreadName); boolean isIncludeClassName(); void setIncludeClassName(boolean includeClassName); JsonLogger trace(); JsonLogger debug(); JsonLogger info(); JsonLogger warn(); JsonLogger error(); static final String TRACE_LEVEL_NAME; static final String DEBUG_LEVEL_NAME; static final String INFO_LEVEL_NAME; static final String WARN_LEVEL_NAME; static final String ERROR_LEVEL_NAME; }
@Test public void testErrorWhenEnabled() throws Exception { Mockito.when(this.slf4jLogger.isErrorEnabled()).thenReturn(true); this.logger.error().message("x-error-msg-x").log(); Mockito.verify(this.slf4jLogger).error(Mockito.contains("\"message\":\"x-error-msg-x\"")); }
@Test public void testErrorWhenDisabled() throws Exception { Mockito.when(this.slf4jLogger.isErrorEnabled()).thenReturn(false); JsonLogger result = this.logger.error(); assertTrue(result instanceof NoopLogger); }