Mercurial > hg > release > thermostat-0.5
changeset 821:2fedc9d961a0
Fix log-handler log-level bound in LoggingUtils.
Earlier the log level of handlers was bound by their respective default config
(INFO for ConsoleHandler). This meant that log messages of a log level lower
than INFO got lost. With this patch the level of handlers is set to the same as
the root. An additional unit test has been added to assert this.
Reviewed-by: omajid
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-December/004397.html
author | Severin Gehwolf <sgehwolf@redhat.com> |
---|---|
date | Thu, 06 Dec 2012 18:31:38 +0100 |
parents | 4d052647a64a |
children | e236c83449c6 |
files | common/core/src/main/java/com/redhat/thermostat/common/utils/LoggingUtils.java common/core/src/test/java/com/redhat/thermostat/common/utils/LoggingUtilsTest.java |
diffstat | 2 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/common/core/src/main/java/com/redhat/thermostat/common/utils/LoggingUtils.java Thu Dec 06 18:30:10 2012 -0500 +++ b/common/core/src/main/java/com/redhat/thermostat/common/utils/LoggingUtils.java Thu Dec 06 18:31:38 2012 +0100 @@ -170,6 +170,7 @@ @SuppressWarnings("rawtypes") Class clazz = ClassLoader.getSystemClassLoader().loadClass(clazzName); Handler handler = (Handler)clazz.newInstance(); + handler.setLevel(root.getLevel()); root.addHandler(handler); } catch (Exception e) { System.err.print("Could not load log-handler '" + clazzName + "'");
--- a/common/core/src/test/java/com/redhat/thermostat/common/utils/LoggingUtilsTest.java Thu Dec 06 18:30:10 2012 -0500 +++ b/common/core/src/test/java/com/redhat/thermostat/common/utils/LoggingUtilsTest.java Thu Dec 06 18:31:38 2012 +0100 @@ -85,7 +85,20 @@ assertEquals(SimpleFormatter.class.getName(), handler.getFormatter().getClass().getName()); assertEquals(Level.WARNING.getName(), rootLogger.getLevel().getName()); assertEquals(Level.OFF.getName(), mongodbLogger.getLevel().getName()); - + } + + @Test + public void testHandlersHaveSameLogLevelAsRoot() throws Exception { + LoggingUtils.loadConfig(GLOBAL_CONFIG); + Logger rootLogger = logManager.getLogger(LoggingUtils.ROOTNAME); + FileHandler handler = (FileHandler)getLogHandler(rootLogger, FileHandler.class); + assertEquals(Level.WARNING, rootLogger.getLevel()); + assertEquals(rootLogger.getLevel(), handler.getLevel()); + LoggingUtils.loadConfig(USER_CONFIG); + rootLogger = logManager.getLogger(LoggingUtils.ROOTNAME); + ConsoleHandler handler2 = (ConsoleHandler)getLogHandler(rootLogger, ConsoleHandler.class); + assertEquals(Level.FINEST, rootLogger.getLevel()); + assertEquals(rootLogger.getLevel(), handler2.getLevel()); } @Test