Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2011-10-20 21:47:26 +0000
committerJoakim Erdfelt2011-10-20 21:47:26 +0000
commit385bc157268f927aac5922bddd695897e5357214 (patch)
treee8e05bb303d3beb692ad9b46d1d88499a1775a56
parentb0a9ec30f9582866543b4bd68a525ca9ece7e621 (diff)
downloadorg.eclipse.jetty.project-385bc157268f927aac5922bddd695897e5357214.tar.gz
org.eclipse.jetty.project-385bc157268f927aac5922bddd695897e5357214.tar.xz
org.eclipse.jetty.project-385bc157268f927aac5922bddd695897e5357214.zip
358649 - Replace existing StdErrLog system properties for DEBUG/IGNORED with LEVEL instead.
Adding special case for "log.LEVEL" to set the root logging level.
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java47
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java32
2 files changed, 55 insertions, 24 deletions
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 87d8530205..d2457c10f2 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
@@ -141,27 +141,44 @@ public class StdErrLog implements Logger
}
else
{
- if ("ALL".equalsIgnoreCase(levelStr.trim()))
+ int level = getLevelId(levelStr);
+ if (level != (-1))
{
- return LEVEL_ALL;
- }
- else if ("DEBUG".equalsIgnoreCase(levelStr.trim()))
- {
- return LEVEL_DEBUG;
- }
- else if ("INFO".equalsIgnoreCase(levelStr.trim()))
- {
- return LEVEL_INFO;
- }
- else if ("WARN".equalsIgnoreCase(levelStr.trim()))
- {
- return LEVEL_WARN;
+ return level;
}
}
}
// Default Logging Level
- return LEVEL_INFO;
+ return getLevelId(props.getProperty("log.LEVEL", "INFO"));
+ }
+
+ protected static int getLevelId(String levelName)
+ {
+ if (levelName == null)
+ {
+ return -1;
+ }
+ String levelStr = levelName.trim();
+ if ("ALL".equalsIgnoreCase(levelStr))
+ {
+ return LEVEL_ALL;
+ }
+ else if ("DEBUG".equalsIgnoreCase(levelStr))
+ {
+ return LEVEL_DEBUG;
+ }
+ else if ("INFO".equalsIgnoreCase(levelStr))
+ {
+ return LEVEL_INFO;
+ }
+ else if ("WARN".equalsIgnoreCase(levelStr))
+ {
+ return LEVEL_WARN;
+ }
+
+ System.err.println("Unknown StdErrLog level [" + 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 913acb0682..12b15ca0b1 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
@@ -79,6 +79,19 @@ public class StdErrLogTest
}
@Test
+ public void testGetLoggingLevel_Root()
+ {
+ Properties props = new Properties();
+ props.setProperty("log.LEVEL","DEBUG");
+
+ // Default Levels
+ Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,null));
+ Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,""));
+ Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty"));
+ Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,StdErrLogTest.class.getName()));
+ }
+
+ @Test
public void testGetLoggingLevel_FQCN()
{
String name = StdErrLogTest.class.getName();
@@ -117,20 +130,21 @@ public class StdErrLogTest
public void testGetLoggingLevel_MixedLevels()
{
Properties props = new Properties();
- props.setProperty("org.eclipse.jetty.util.LEVEL","DEBUG");
+ props.setProperty("log.LEVEL","DEBUG");
+ props.setProperty("org.eclipse.jetty.util.LEVEL","WARN");
props.setProperty("org.eclipse.jetty.util.ConcurrentHashMap.LEVEL","ALL");
// Default Levels
- Assert.assertEquals(StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,null));
- Assert.assertEquals(StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,""));
- Assert.assertEquals(StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty"));
- Assert.assertEquals(StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.server.ServerObject"));
+ Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,null));
+ Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,""));
+ Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty"));
+ Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.server.ServerObject"));
// Configured Level
- Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,StdErrLogTest.class.getName()));
- Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util.MagicUtil"));
- Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util"));
- Assert.assertEquals(StdErrLog.LEVEL_DEBUG,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util.resource.FileResource"));
+ Assert.assertEquals(StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,StdErrLogTest.class.getName()));
+ Assert.assertEquals(StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util.MagicUtil"));
+ Assert.assertEquals(StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util"));
+ Assert.assertEquals(StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util.resource.FileResource"));
Assert.assertEquals(StdErrLog.LEVEL_ALL,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.util.ConcurrentHashMap"));
}

Back to the top