@Test public void testLoggerNameWithNumbers() { final String name = "some_logger_name"; final String logger = "org.ops4j.pax.web"; final String level = "WARN"; final Dictionary<String, Object> config = new Hashtable<>(); config.put(ROOT_LOGGER, "INFO"); config.put(LOGGER_PREFIX + name + NAME_SUFFIX, logger); config.put(LOGGER_PREFIX + name + LEVEL_SUFFIX, level); final LogServiceInternal logServiceInternal = new LogServiceLog4j2Impl(config); assertThat(logServiceInternal.getLevel(logger), hasEntry(logger, level)); }
public Map<String, String> getLevel(String logger) { Map<String, String> loggers = new TreeMap<>(); String root = (String) config.get(ROOT_LOGGER_LEVEL); loggers.put(ROOT_LOGGER, root); if (ROOT_LOGGER.equals(logger)) { return loggers; } Map<String, String> names = new HashMap<>(); Map<String, String> levels = new HashMap<>(); for (String key : config.keySet()) { String loggerName = getMatching(namePattern, key); if (loggerName != null) { names.put(loggerName, config.get(key).toString()); } loggerName = getMatching(levelPattern, key); if (loggerName != null) { levels.put(loggerName, config.get(key).toString()); } } for (Map.Entry<String, String> e : names.entrySet()) { loggers.put(e.getValue(), levels.get(e.getKey())); } if (ALL_LOGGER.equalsIgnoreCase(logger)) { return loggers; } String l = logger; String val; for (;;) { val = loggers.get(l != null ? l : ROOT_LOGGER); if (val != null || l == null) { return Collections.singletonMap(logger, val); } int idx = l.lastIndexOf('.'); if (idx < 0) { l = null; } else { l = l.substring(0, idx); } } }
LogServiceLog4j2Impl implements LogServiceInternal { public Map<String, String> getLevel(String logger) { Map<String, String> loggers = new TreeMap<>(); String root = (String) config.get(ROOT_LOGGER_LEVEL); loggers.put(ROOT_LOGGER, root); if (ROOT_LOGGER.equals(logger)) { return loggers; } Map<String, String> names = new HashMap<>(); Map<String, String> levels = new HashMap<>(); for (String key : config.keySet()) { String loggerName = getMatching(namePattern, key); if (loggerName != null) { names.put(loggerName, config.get(key).toString()); } loggerName = getMatching(levelPattern, key); if (loggerName != null) { levels.put(loggerName, config.get(key).toString()); } } for (Map.Entry<String, String> e : names.entrySet()) { loggers.put(e.getValue(), levels.get(e.getKey())); } if (ALL_LOGGER.equalsIgnoreCase(logger)) { return loggers; } String l = logger; String val; for (;;) { val = loggers.get(l != null ? l : ROOT_LOGGER); if (val != null || l == null) { return Collections.singletonMap(logger, val); } int idx = l.lastIndexOf('.'); if (idx < 0) { l = null; } else { l = l.substring(0, idx); } } } }
LogServiceLog4j2Impl implements LogServiceInternal { public Map<String, String> getLevel(String logger) { Map<String, String> loggers = new TreeMap<>(); String root = (String) config.get(ROOT_LOGGER_LEVEL); loggers.put(ROOT_LOGGER, root); if (ROOT_LOGGER.equals(logger)) { return loggers; } Map<String, String> names = new HashMap<>(); Map<String, String> levels = new HashMap<>(); for (String key : config.keySet()) { String loggerName = getMatching(namePattern, key); if (loggerName != null) { names.put(loggerName, config.get(key).toString()); } loggerName = getMatching(levelPattern, key); if (loggerName != null) { levels.put(loggerName, config.get(key).toString()); } } for (Map.Entry<String, String> e : names.entrySet()) { loggers.put(e.getValue(), levels.get(e.getKey())); } if (ALL_LOGGER.equalsIgnoreCase(logger)) { return loggers; } String l = logger; String val; for (;;) { val = loggers.get(l != null ? l : ROOT_LOGGER); if (val != null || l == null) { return Collections.singletonMap(logger, val); } int idx = l.lastIndexOf('.'); if (idx < 0) { l = null; } else { l = l.substring(0, idx); } } } LogServiceLog4j2Impl(Dictionary<String, Object> config); }
LogServiceLog4j2Impl implements LogServiceInternal { public Map<String, String> getLevel(String logger) { Map<String, String> loggers = new TreeMap<>(); String root = (String) config.get(ROOT_LOGGER_LEVEL); loggers.put(ROOT_LOGGER, root); if (ROOT_LOGGER.equals(logger)) { return loggers; } Map<String, String> names = new HashMap<>(); Map<String, String> levels = new HashMap<>(); for (String key : config.keySet()) { String loggerName = getMatching(namePattern, key); if (loggerName != null) { names.put(loggerName, config.get(key).toString()); } loggerName = getMatching(levelPattern, key); if (loggerName != null) { levels.put(loggerName, config.get(key).toString()); } } for (Map.Entry<String, String> e : names.entrySet()) { loggers.put(e.getValue(), levels.get(e.getKey())); } if (ALL_LOGGER.equalsIgnoreCase(logger)) { return loggers; } String l = logger; String val; for (;;) { val = loggers.get(l != null ? l : ROOT_LOGGER); if (val != null || l == null) { return Collections.singletonMap(logger, val); } int idx = l.lastIndexOf('.'); if (idx < 0) { l = null; } else { l = l.substring(0, idx); } } } LogServiceLog4j2Impl(Dictionary<String, Object> config); Map<String, String> getLevel(String logger); void setLevel(String logger, String level); }
LogServiceLog4j2Impl implements LogServiceInternal { public Map<String, String> getLevel(String logger) { Map<String, String> loggers = new TreeMap<>(); String root = (String) config.get(ROOT_LOGGER_LEVEL); loggers.put(ROOT_LOGGER, root); if (ROOT_LOGGER.equals(logger)) { return loggers; } Map<String, String> names = new HashMap<>(); Map<String, String> levels = new HashMap<>(); for (String key : config.keySet()) { String loggerName = getMatching(namePattern, key); if (loggerName != null) { names.put(loggerName, config.get(key).toString()); } loggerName = getMatching(levelPattern, key); if (loggerName != null) { levels.put(loggerName, config.get(key).toString()); } } for (Map.Entry<String, String> e : names.entrySet()) { loggers.put(e.getValue(), levels.get(e.getKey())); } if (ALL_LOGGER.equalsIgnoreCase(logger)) { return loggers; } String l = logger; String val; for (;;) { val = loggers.get(l != null ? l : ROOT_LOGGER); if (val != null || l == null) { return Collections.singletonMap(logger, val); } int idx = l.lastIndexOf('.'); if (idx < 0) { l = null; } else { l = l.substring(0, idx); } } } LogServiceLog4j2Impl(Dictionary<String, Object> config); Map<String, String> getLevel(String logger); void setLevel(String logger, String level);  }