362113 - Improve Test Coverage of org.eclipse.jetty.util.log classes

* Fixing bugs with bad level names, and adding tests for lowercase level
  names.
This commit is contained in:
Joakim Erdfelt 2011-10-26 11:04:53 -07:00
parent 064c93c53b
commit 1f9814a69a
2 changed files with 40 additions and 18 deletions

View File

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

View File

@ -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()
{