LogWriterImpl implements InternalLogWriter { public static int levelNameToCode(String levelName) { if ("all".equalsIgnoreCase(levelName)) { return ALL_LEVEL; } if ("finest".equalsIgnoreCase(levelName) || "trace".equalsIgnoreCase(levelName)) { return FINEST_LEVEL; } if ("finer".equalsIgnoreCase(levelName)) { return FINER_LEVEL; } if ("fine".equalsIgnoreCase(levelName) || "debug".equalsIgnoreCase(levelName)) { return FINE_LEVEL; } if ("config".equalsIgnoreCase(levelName)) { return CONFIG_LEVEL; } if ("info".equalsIgnoreCase(levelName)) { return INFO_LEVEL; } if ("warning".equalsIgnoreCase(levelName) || "warn".equalsIgnoreCase(levelName)) { return WARNING_LEVEL; } if ("error".equalsIgnoreCase(levelName)) { return ERROR_LEVEL; } if ("severe".equalsIgnoreCase(levelName) || "fatal".equalsIgnoreCase(levelName)) { return SEVERE_LEVEL; } if ("none".equalsIgnoreCase(levelName)) { return NONE_LEVEL; } try { if (levelName.startsWith("level-")) { String levelValue = levelName.substring("level-".length()); return Integer.parseInt(levelValue); } } catch (NullPointerException | NumberFormatException ignore) { } throw new IllegalArgumentException( "Unknown log-level \"" + levelName + "\". Valid levels are: " + join(levelNames) + "."); } protected  LogWriterImpl(); @Override abstract int getLogWriterLevel(); @Override boolean isSecure(); static String allowedLogLevels(); static String levelToString(int level); static String join(Object[] array); static String join(Object[] array, String joinString); static String join(List<?> list); static String join(List<?> list, String joinString); static int levelNameToCode(String levelName); @Override boolean severeEnabled(); @Override void severe(String message, Throwable throwable); @Override void severe(String message); @Override void severe(Throwable throwable); @Override void severe(StringId messageId, Object[] parameters, Throwable throwable); @Override void severe(StringId messageId, Object parameter, Throwable throwable); @Override void severe(StringId messageId, Throwable throwable); @Override void severe(StringId messageId, Object[] parameters); @Override void severe(StringId messageId, Object parameter); @Override void severe(StringId messageId); @Override boolean errorEnabled(); @Override void error(String message, Throwable throwable); @Override void error(String message); @Override void error(Throwable throwable); @Override void error(StringId messageId, Object[] parameters, Throwable throwable); @Override void error(StringId messageId, Object parameter, Throwable throwable); @Override void error(StringId messageId, Throwable throwable); @Override void error(StringId messageId, Object[] parameters); @Override void error(StringId messageId, Object parameter); @Override void error(StringId messageId); @Override boolean warningEnabled(); @Override void warning(String message, Throwable throwable); @Override void warning(String message); @Override void warning(Throwable throwable); @Override void warning(StringId messageId, Object[] parameters, Throwable throwable); @Override void warning(StringId messageId, Object parameter, Throwable throwable); @Override void warning(StringId messageId, Throwable throwable); @Override void warning(StringId messageId, Object[] parameters); @Override void warning(StringId messageId, Object parameter); @Override void warning(StringId messageId); @Override boolean infoEnabled(); @Override void info(String message, Throwable throwable); @Override void info(String message); @Override void info(Throwable throwable); @Override void info(StringId messageId, Object[] parameters, Throwable throwable); @Override void info(StringId messageId, Object parameter, Throwable throwable); @Override void info(StringId messageId, Throwable throwable); @Override void info(StringId messageId, Object[] parameters); @Override void info(StringId messageId, Object parameter); @Override void info(StringId messageId); @Override boolean configEnabled(); @Override void config(String message, Throwable throwable); @Override void config(String message); @Override void config(Throwable throwable); @Override void config(StringId messageId, Object[] parameters, Throwable throwable); @Override void config(StringId messageId, Object parameter, Throwable throwable); @Override void config(StringId messageId, Throwable throwable); @Override void config(StringId messageId, Object[] parameters); @Override void config(StringId messageId, Object parameter); @Override void config(StringId messageId); @Override boolean fineEnabled(); @Override void fine(String message, Throwable throwable); @Override void fine(String message); @Override void fine(Throwable throwable); @Override boolean finerEnabled(); @Override void finer(String message, Throwable throwable); @Override void finer(String message); @Override void finer(Throwable throwable); @Override void entering(String sourceClass, String sourceMethod); @Override void exiting(String sourceClass, String sourceMethod); @Override void throwing(String sourceClass, String sourceMethod, Throwable thrown); @Override boolean finestEnabled(); @Override void finest(String message, Throwable throwable); @Override void finest(String message); @Override void finest(Throwable throwable); void startup(StringId msgID, Object[] params); @Override abstract void put(int messageLevel, String message, Throwable throwable); @Override abstract void put(int messageLevel, StringId messageId, Object[] parameters,
      Throwable throwable); void log(int level, String message, Throwable thrown); void log(int level, String message); @Override Handler getHandler(); static String getStackTrace(Throwable throwable); void logTraces(final boolean toStdout, final Thread targetThread, final int interval,
      final AtomicBoolean done); static StringBuilder getStackTrace(Thread targetThread); @Override LogWriter convertToLogWriter(); @Override LogWriterI18n convertToLogWriterI18n(); static void setStartupListener(StartupStatusListener mainListener); static StartupStatusListener getStartupListener();  }
@Test public void testLevelNameToCode() { assertThat(LogWriterImpl.levelNameToCode("all")).isEqualTo(Integer.MIN_VALUE); assertThat(LogWriterImpl.levelNameToCode("finest")).isEqualTo(300); assertThat(LogWriterImpl.levelNameToCode("trace")).isEqualTo(300); assertThat(LogWriterImpl.levelNameToCode("finer")).isEqualTo(400); assertThat(LogWriterImpl.levelNameToCode("fine")).isEqualTo(500); assertThat(LogWriterImpl.levelNameToCode("debug")).isEqualTo(500); assertThat(LogWriterImpl.levelNameToCode("config")).isEqualTo(700); assertThat(LogWriterImpl.levelNameToCode("info")).isEqualTo(800); assertThat(LogWriterImpl.levelNameToCode("warning")).isEqualTo(900); assertThat(LogWriterImpl.levelNameToCode("warn")).isEqualTo(900); assertThat(LogWriterImpl.levelNameToCode("error")).isEqualTo(950); assertThat(LogWriterImpl.levelNameToCode("severe")).isEqualTo(1000); assertThat(LogWriterImpl.levelNameToCode("fatal")).isEqualTo(1000); assertThat(LogWriterImpl.levelNameToCode("none")).isEqualTo(Integer.MAX_VALUE); }