Logging { public static void log(@NotNull final Level level, @NotNull final String message, @NotNull final Object... args) { pluginLogger.log(level, message, args); } private  Logging(); @NotNull static PluginLogger getLogger(); static void setDebugLevel(final int debugLevel); static void log(@NotNull final Level level, @NotNull final String message, @NotNull final Object... args); static void fine(@NotNull final String message, @NotNull final Object...args); static void finer(@NotNull final String message, @NotNull final Object...args); static void finest(@NotNull final String message, @NotNull final Object...args); static void config(@NotNull final String message, @NotNull final Object...args); static void info(@NotNull final String message, @NotNull final Object...args); static void warning(@NotNull final String message, @NotNull final Object...args); static void severe(@NotNull final String message, @NotNull final Object...args);  }
@Test public void testLog() throws Exception { assertEquals(logging, Logging.getLogger()); logging.setDebugLevel(3); logging.logger.getParent().addHandler(parentHandler); logging.logger.addHandler(handler); tester = new RecordTester() { @Override public void test(LogRecord record) { assertEquals(logging.getPrefixedMessage(SIMPLE_MESSAGE), record.getMessage()); } }; level = Level.INFO; logging.log(Level.INFO, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.WARNING; level = Level.WARNING; logging.log(Level.WARNING, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.SEVERE; level = Level.SEVERE; logging.log(Level.SEVERE, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.INFO; level = Level.INFO; logging.log(Level.CONFIG, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); handler.flush(); parentHandler.flush(); level = Level.INFO; level = Level.INFO; Logging.info(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.WARNING; level = Level.WARNING; Logging.warning(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.SEVERE; level = Level.SEVERE; Logging.severe(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.INFO; level = Level.INFO; Logging.config(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); assertTrue(parentHandler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); handler.flush(); parentHandler.flush(); tester = new RecordTester() { @Override public void test(LogRecord record) { assertEquals(logging.getPrefixedMessage(SIMPLE_MESSAGE), record.getMessage()); } }; level = Level.INFO; logging.log(Level.INFO, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); Logging.info(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.WARNING; logging.log(Level.WARNING, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); Logging.warning(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.SEVERE; logging.log(Level.SEVERE, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); Logging.severe(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); level = Level.INFO; logging.log(Level.CONFIG, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); Logging.config(SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getPrefixedMessage(SIMPLE_MESSAGE))); handler.flush(); tester = new RecordTester() { @Override public void test(LogRecord record) { assertEquals(logging.getDebugString(SIMPLE_MESSAGE), record.getMessage()); } }; level = Level.INFO; logging.log(Level.FINE, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); logging.log(Level.FINER, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); logging.log(Level.FINEST, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); logging.log(Level.FINE, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); logging.log(Level.FINER, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); logging.log(Level.FINEST, SIMPLE_MESSAGE); assertTrue(handler.hasMessage(level, logging.getDebugString(SIMPLE_MESSAGE))); handler.flush(); final Object o = new Object(); tester = new RecordTester() { @Override public void test(LogRecord record) { assertEquals(logging.getPrefixedMessage(String.format(ARGS_MESSAGE, "poop", 2, o)), record.getMessage()); } }; level = Level.INFO; logging.log(Level.INFO, ARGS_MESSAGE, "poop", 2, o); tester = new RecordTester() { @Override public void test(LogRecord record) { assertEquals(logging.getPrefixedMessage(ARGS_MESSAGE), record.getMessage()); } }; level = Level.INFO; logging.log(Level.INFO, ARGS_MESSAGE, "poop", 2); }