diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index d0c6bdee1b9..3af51a38cf4 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -126,34 +126,32 @@ public class StdErrLog implements Logger { String levelStr = props.getProperty(nameSegment + ".LEVEL"); // System.err.printf("[StdErrLog.CONFIG] Checking for property [%s.LEVEL] = %s%n",nameSegment,levelStr); - if (levelStr == null) + if (levelStr != null) { - // Trim and try again. - int idx = nameSegment.lastIndexOf('.'); - if (idx >= 0) - { - nameSegment = nameSegment.substring(0,idx); - } - else - { - nameSegment = null; - } - } - else - { - int level = getLevelId(levelStr); + int level = getLevelId(nameSegment + ".LEVEL", levelStr); if (level != (-1)) { return level; } } + + // Trim and try again. + int idx = nameSegment.lastIndexOf('.'); + if (idx >= 0) + { + nameSegment = nameSegment.substring(0,idx); + } + else + { + nameSegment = null; + } } // Default Logging Level - return getLevelId(props.getProperty("log.LEVEL", "INFO")); + return getLevelId("log.LEVEL", props.getProperty("log.LEVEL", "INFO")); } - protected static int getLevelId(String levelName) + protected static int getLevelId(String levelSegment, String levelName) { if (levelName == null) { @@ -177,7 +175,7 @@ public class StdErrLog implements Logger return LEVEL_WARN; } - System.err.println("Unknown StdErrLog level [" + levelStr + "], expecting only [ALL, DEBUG, INFO, WARN] as values."); + System.err.println("Unknown StdErrLog level [" + levelSegment + "]=[" + levelStr + "], expecting only [ALL, DEBUG, INFO, WARN] as values."); return -1; } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java index bc6899588b5..ade997383c1 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java @@ -78,6 +78,30 @@ public class StdErrLogTest Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,StdErrLogTest.class.getName())); } + @Test + public void testGetLoggingLevel_Bad() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "WARN"); + props.setProperty("org.eclipse.jetty.bad.LEVEL","FRUIT"); + + // Default Level (because of bad level value) + Assert.assertEquals("Bad Logging Level",StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.bad")); + } + + @Test + public void testGetLoggingLevel_Lowercase() + { + Properties props = new Properties(); + props.setProperty("log.LEVEL", "warn"); + props.setProperty("org.eclipse.jetty.util.LEVEL","info"); + + // Default Level + Assert.assertEquals("Lowercase Level",StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty")); + // Specific Level + Assert.assertEquals("Lowercase Level",StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util")); + } + @Test public void testGetLoggingLevel_Root() {