358649 - Replace existing StdErrLog system properties for DEBUG/IGNORED with LEVEL instead.

Adding special case for "log.LEVEL" to set the root logging level.
This commit is contained in:
Joakim Erdfelt 2011-10-20 14:47:26 -07:00
parent b0a9ec30f9
commit 385bc15726
2 changed files with 55 additions and 24 deletions

View File

@ -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;
}
/**

View File

@ -78,6 +78,19 @@ public class StdErrLogTest
Assert.assertEquals("Default Logging Level",StdErrLog.LEVEL_INFO,StdErrLog.getLoggingLevel(props,StdErrLogTest.class.getName()));
}
@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()
{
@ -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"));
}