/** * Set the level of the logger. If the new level is null, the logger will inherit it's level from its nearest ancestor with a non-null * level. */ public static void setLevel(Logger logger, String level) { final Level l; if (level == null) { l = null; } else { l = Level.valueOf(level); } setLevel(logger, l); }
/** * Reset the logging levels to the state provided by the map. * * @param map the logging levels to apply * @return an empty map */ private Map<String, String> reset(final Map<String, String> map) { for (final Map.Entry<String, String> previousLogger : map.entrySet()) { final Logger logger = resolveLogger(previousLogger.getKey()); ServerLoggers.setLevel(logger, previousLogger.getValue()); } return Collections.emptyMap(); } }
/** * Applies the test logging annotation and returns the existing logging levels. * * @param testLogging the test logging annotation to apply * @return the existing logging levels */ private Map<String, String> processTestLogging(final TestLogging testLogging) { final Map<String, String> map = getLoggersAndLevelsFromAnnotation(testLogging); if (map == null) { return Collections.emptyMap(); } // obtain the existing logging levels so that we can restore them at the end of the test; we have to do this separately from setting // the logging levels so that setting foo does not impact the logging level for foo.bar when we check the existing logging level for // for.bar final Map<String, String> existing = new TreeMap<>(); for (final Map.Entry<String, String> entry : map.entrySet()) { final Logger logger = resolveLogger(entry.getKey()); existing.put(entry.getKey(), logger.getLevel().toString()); } for (final Map.Entry<String, String> entry : map.entrySet()) { final Logger logger = resolveLogger(entry.getKey()); ServerLoggers.setLevel(logger, entry.getValue()); } return existing; }