LogContext implements LoggingApi<API>, LogData { @Override public final void log() { if (shouldLog()) logImpl(LITERAL_VALUE_MESSAGE, ""); } protected  LogContext(Level level, boolean isForced); protected  LogContext(Level level, boolean isForced, long timestampNanos); @Override final Level getLevel(); @Deprecated @Override final long getTimestampMicros(); @Override final long getTimestampNanos(); @Override final String getLoggerName(); @Override final LogSite getLogSite(); @Override final TemplateContext getTemplateContext(); @Override final Object[] getArguments(); @Override final Object getLiteralArgument(); @Override final boolean wasForced(); @Override final Metadata getMetadata(); @Override final API withInjectedLogSite(LogSite logSite); @SuppressWarnings("deprecation") @Override final API withInjectedLogSite(
      String internalClassName,
      String methodName,
      int encodedLineNumber,
      @NullableDecl String sourceFileName); @Override final boolean isEnabled(); @Override final API with(MetadataKey<T> key, @NullableDecl T value); @Override final API with(MetadataKey<Boolean> key); @Override final API withCause(Throwable cause); @Override API withStackTrace(StackSize size); @Override final API every(int n); @Override final API atMostEvery(int n, TimeUnit unit); @Override final void log(); @Override final void log(String msg); @Override final void log(String message, @NullableDecl Object p1); @Override final void log(String message, @NullableDecl Object p1, @NullableDecl Object p2); @Override final void log(
      String message, @NullableDecl Object p1, @NullableDecl Object p2, @NullableDecl Object p3); @Override final void log(
      String message,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9,
      @NullableDecl Object p10); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9,
      @NullableDecl Object p10,
      Object... rest); @Override final void log(String message, char p1); @Override final void log(String message, byte p1); @Override final void log(String message, short p1); @Override final void log(String message, int p1); @Override final void log(String message, long p1); @Override final void log(String message, @NullableDecl Object p1, boolean p2); @Override final void log(String message, @NullableDecl Object p1, char p2); @Override final void log(String message, @NullableDecl Object p1, byte p2); @Override final void log(String message, @NullableDecl Object p1, short p2); @Override final void log(String message, @NullableDecl Object p1, int p2); @Override final void log(String message, @NullableDecl Object p1, long p2); @Override final void log(String message, @NullableDecl Object p1, float p2); @Override final void log(String message, @NullableDecl Object p1, double p2); @Override final void log(String message, boolean p1, @NullableDecl Object p2); @Override final void log(String message, char p1, @NullableDecl Object p2); @Override final void log(String message, byte p1, @NullableDecl Object p2); @Override final void log(String message, short p1, @NullableDecl Object p2); @Override final void log(String message, int p1, @NullableDecl Object p2); @Override final void log(String message, long p1, @NullableDecl Object p2); @Override final void log(String message, float p1, @NullableDecl Object p2); @Override final void log(String message, double p1, @NullableDecl Object p2); @Override final void log(String message, boolean p1, boolean p2); @Override final void log(String message, char p1, boolean p2); @Override final void log(String message, byte p1, boolean p2); @Override final void log(String message, short p1, boolean p2); @Override final void log(String message, int p1, boolean p2); @Override final void log(String message, long p1, boolean p2); @Override final void log(String message, float p1, boolean p2); @Override final void log(String message, double p1, boolean p2); @Override final void log(String message, boolean p1, char p2); @Override final void log(String message, char p1, char p2); @Override final void log(String message, byte p1, char p2); @Override final void log(String message, short p1, char p2); @Override final void log(String message, int p1, char p2); @Override final void log(String message, long p1, char p2); @Override final void log(String message, float p1, char p2); @Override final void log(String message, double p1, char p2); @Override final void log(String message, boolean p1, byte p2); @Override final void log(String message, char p1, byte p2); @Override final void log(String message, byte p1, byte p2); @Override final void log(String message, short p1, byte p2); @Override final void log(String message, int p1, byte p2); @Override final void log(String message, long p1, byte p2); @Override final void log(String message, float p1, byte p2); @Override final void log(String message, double p1, byte p2); @Override final void log(String message, boolean p1, short p2); @Override final void log(String message, char p1, short p2); @Override final void log(String message, byte p1, short p2); @Override final void log(String message, short p1, short p2); @Override final void log(String message, int p1, short p2); @Override final void log(String message, long p1, short p2); @Override final void log(String message, float p1, short p2); @Override final void log(String message, double p1, short p2); @Override final void log(String message, boolean p1, int p2); @Override final void log(String message, char p1, int p2); @Override final void log(String message, byte p1, int p2); @Override final void log(String message, short p1, int p2); @Override final void log(String message, int p1, int p2); @Override final void log(String message, long p1, int p2); @Override final void log(String message, float p1, int p2); @Override final void log(String message, double p1, int p2); @Override final void log(String message, boolean p1, long p2); @Override final void log(String message, char p1, long p2); @Override final void log(String message, byte p1, long p2); @Override final void log(String message, short p1, long p2); @Override final void log(String message, int p1, long p2); @Override final void log(String message, long p1, long p2); @Override final void log(String message, float p1, long p2); @Override final void log(String message, double p1, long p2); @Override final void log(String message, boolean p1, float p2); @Override final void log(String message, char p1, float p2); @Override final void log(String message, byte p1, float p2); @Override final void log(String message, short p1, float p2); @Override final void log(String message, int p1, float p2); @Override final void log(String message, long p1, float p2); @Override final void log(String message, float p1, float p2); @Override final void log(String message, double p1, float p2); @Override final void log(String message, boolean p1, double p2); @Override final void log(String message, char p1, double p2); @Override final void log(String message, byte p1, double p2); @Override final void log(String message, short p1, double p2); @Override final void log(String message, int p1, double p2); @Override final void log(String message, long p1, double p2); @Override final void log(String message, float p1, double p2); @Override final void log(String message, double p1, double p2); @Override final void logVarargs(String message, @NullableDecl Object[] params);  }
@Test public void testLazyArgs() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log("Hello %s", LazyArgs.lazy(() -> "World")); logger.atFine().log( "Hello %s", LazyArgs.lazy( () -> { throw new RuntimeException( "Lazy arguments should not be evaluated in a disabled log statement"); })); backend.assertLastLogged().hasMessage("Hello %s"); backend.assertLastLogged().hasArguments("World"); }
@Test public void testNoArguments() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log(); backend.assertLastLogged().hasMessage(""); backend.assertLastLogged().hasArguments(); }
@SuppressWarnings("FormatString") @Test public void testLiteralArgument() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log("Hello %s World"); backend.assertLastLogged().hasMessage("Hello %s World"); backend.assertLastLogged().hasArguments(); }
@Test public void testSingleParameter() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log("Hello %d World", 42); backend.assertLastLogged().hasMessage("Hello %d World"); backend.assertLastLogged().hasArguments(42); }
@Test public void testNullLiteral() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log((String) null); backend.assertLastLogged().hasMessage(null); }
@Test public void testNullArgument() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); logger.atInfo().log("Hello %d World", null); backend.assertLastLogged().hasMessage("Hello %d World"); backend.assertLastLogged().hasArguments(new Object[] {null}); }
@Test public void testNullMessageAndArgument() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); try { logger.atInfo().log(null, null); fail("null message and arguments should fail"); } catch (NullPointerException expected) { } }
@Test public void testManyObjectParameters() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); String ms = "Any message will do..."; logger.atInfo().log(ms, "1"); backend.assertLastLogged().hasArguments("1"); logger.atInfo().log(ms, "1", "2"); backend.assertLastLogged().hasArguments("1", "2"); logger.atInfo().log(ms, "1", "2", "3"); backend.assertLastLogged().hasArguments("1", "2", "3"); logger.atInfo().log(ms, "1", "2", "3", "4"); backend.assertLastLogged().hasArguments("1", "2", "3", "4"); logger.atInfo().log(ms, "1", "2", "3", "4", "5"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5", "6"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5", "6", "7"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7", "8"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5", "6", "7", "8"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7", "8", "9"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5", "6", "7", "8", "9"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); backend.assertLastLogged().hasArguments("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"); backend .assertLastLogged() .hasArguments("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"); logger.atInfo().log(ms, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"); backend .assertLastLogged() .hasArguments("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"); }
@Test public void testOneUnboxedArgument() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); String ms = "Any message will do..."; logger.atInfo().log(ms, BYTE_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG); logger.atInfo().log(ms, SHORT_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG); logger.atInfo().log(ms, INT_ARG); backend.assertLastLogged().hasArguments(INT_ARG); logger.atInfo().log(ms, LONG_ARG); backend.assertLastLogged().hasArguments(LONG_ARG); logger.atInfo().log(ms, CHAR_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG); }
@Test public void testTwoUnboxedArguments() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); String ms = "Any message will do..."; logger.atInfo().log(ms, BYTE_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, BYTE_ARG); logger.atInfo().log(ms, BYTE_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, SHORT_ARG); logger.atInfo().log(ms, BYTE_ARG, INT_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, INT_ARG); logger.atInfo().log(ms, BYTE_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, LONG_ARG); logger.atInfo().log(ms, BYTE_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, CHAR_ARG); logger.atInfo().log(ms, SHORT_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, BYTE_ARG); logger.atInfo().log(ms, SHORT_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, SHORT_ARG); logger.atInfo().log(ms, SHORT_ARG, INT_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, INT_ARG); logger.atInfo().log(ms, SHORT_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, LONG_ARG); logger.atInfo().log(ms, SHORT_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, CHAR_ARG); logger.atInfo().log(ms, INT_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(INT_ARG, BYTE_ARG); logger.atInfo().log(ms, INT_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(INT_ARG, SHORT_ARG); logger.atInfo().log(ms, INT_ARG, INT_ARG); backend.assertLastLogged().hasArguments(INT_ARG, INT_ARG); logger.atInfo().log(ms, INT_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(INT_ARG, LONG_ARG); logger.atInfo().log(ms, INT_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(INT_ARG, CHAR_ARG); logger.atInfo().log(ms, LONG_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, BYTE_ARG); logger.atInfo().log(ms, LONG_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, SHORT_ARG); logger.atInfo().log(ms, LONG_ARG, INT_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, INT_ARG); logger.atInfo().log(ms, LONG_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, LONG_ARG); logger.atInfo().log(ms, LONG_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, CHAR_ARG); logger.atInfo().log(ms, CHAR_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, BYTE_ARG); logger.atInfo().log(ms, CHAR_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, SHORT_ARG); logger.atInfo().log(ms, CHAR_ARG, INT_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, INT_ARG); logger.atInfo().log(ms, CHAR_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, LONG_ARG); logger.atInfo().log(ms, CHAR_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, CHAR_ARG); }
@Test public void testTwoMixedArguments() { FakeLoggerBackend backend = new FakeLoggerBackend(); FluentLogger logger = new FluentLogger(backend); String ms = "Any message will do..."; logger.atInfo().log(ms, OBJECT_ARG, BYTE_ARG); backend.assertLastLogged().hasArguments(OBJECT_ARG, BYTE_ARG); logger.atInfo().log(ms, OBJECT_ARG, SHORT_ARG); backend.assertLastLogged().hasArguments(OBJECT_ARG, SHORT_ARG); logger.atInfo().log(ms, OBJECT_ARG, INT_ARG); backend.assertLastLogged().hasArguments(OBJECT_ARG, INT_ARG); logger.atInfo().log(ms, OBJECT_ARG, LONG_ARG); backend.assertLastLogged().hasArguments(OBJECT_ARG, LONG_ARG); logger.atInfo().log(ms, OBJECT_ARG, CHAR_ARG); backend.assertLastLogged().hasArguments(OBJECT_ARG, CHAR_ARG); logger.atInfo().log(ms, BYTE_ARG, OBJECT_ARG); backend.assertLastLogged().hasArguments(BYTE_ARG, OBJECT_ARG); logger.atInfo().log(ms, SHORT_ARG, OBJECT_ARG); backend.assertLastLogged().hasArguments(SHORT_ARG, OBJECT_ARG); logger.atInfo().log(ms, INT_ARG, OBJECT_ARG); backend.assertLastLogged().hasArguments(INT_ARG, OBJECT_ARG); logger.atInfo().log(ms, LONG_ARG, OBJECT_ARG); backend.assertLastLogged().hasArguments(LONG_ARG, OBJECT_ARG); logger.atInfo().log(ms, CHAR_ARG, OBJECT_ARG); backend.assertLastLogged().hasArguments(CHAR_ARG, OBJECT_ARG); }