private static LogConfig loadConfig(Properties props) { final LogLevel.Enum baseLevel = Props.get(props, KEY_BASE_LEVEL, LogLevel.Enum::valueOf, null); final String logServiceClass = Props.get(props, KEY_LOG_SERVICE, String::valueOf, null); final LogConfig config = new LogConfig(); if (baseLevel != null) { config.withBaseLevel(baseLevel.getLevel()); } if (logServiceClass != null && ! logServiceClass.equals(config.getLogService().getClass().getName())) { config.withLogService(instantiateLogService(logServiceClass)); } return config; }
@Override public void log(int level, String tag, String format, int argc, Object[] argv, Throwable throwable, String entrypoint) { final String line; final String levelName = LogLevel.Enum.match(level).getShortName(); final String threadName = Thread.currentThread().getName(); final String time; synchronized (dateFormat) { time = dateFormat.format(new Date()); } final String message = SafeFormat.format(format, argc, argv); final String location = Stacks.formatLocation(Stacks.locate(entrypoint)); if (tag != null) { line = time + " " + levelName + " [" + threadName + "] [" + tag + "] " + location + ": " + message; } else { line = time + " " + levelName + " [" + threadName + "] " + location + ": " + message; } stream.println(line); if (throwable != null) { throwable.printStackTrace(stream); } } }
@Override public LogChain level(int level) { if (isEnabled(level)) { if (level == LogLevel.OFF) throw new IllegalArgumentException("Cannot log at level " + LogLevel.Enum.OFF.name()); final LogChainImpl chain = threadLocalChain.get(); chain.level = level; return chain; } else { return NopLogChain.getInstance(); } }
static Enum match(int level) { return map(level, Enum.values()); } }