Issue #4830 - Improved notification of configuration mistakes on level names
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
1c2c3892f1
commit
69e1d119fe
|
@ -26,6 +26,8 @@ import java.security.PrivilegedAction;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JettyLogger specific configuration:
|
* JettyLogger specific configuration:
|
||||||
|
@ -115,26 +117,39 @@ public class JettyLoggerConfiguration
|
||||||
JettyLevel level = JettyLoggerFactory.walkParentLoggerNames(startName, key ->
|
JettyLevel level = JettyLoggerFactory.walkParentLoggerNames(startName, key ->
|
||||||
{
|
{
|
||||||
String levelStr = properties.getProperty(key + SUFFIX_LEVEL);
|
String levelStr = properties.getProperty(key + SUFFIX_LEVEL);
|
||||||
return JettyLevel.strToLevel(levelStr);
|
return toJettyLevel(key, levelStr);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
// Try slf4j root logging config.
|
// Try slf4j root logging config.
|
||||||
String levelStr = properties.getProperty(JettyLogger.ROOT_LOGGER_NAME + SUFFIX_LEVEL);
|
String levelStr = properties.getProperty(JettyLogger.ROOT_LOGGER_NAME + SUFFIX_LEVEL);
|
||||||
level = JettyLevel.strToLevel(levelStr);
|
level = toJettyLevel(JettyLogger.ROOT_LOGGER_NAME, levelStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
// Try legacy root logging config.
|
// Try legacy root logging config.
|
||||||
String levelStr = properties.getProperty("log" + SUFFIX_LEVEL);
|
String levelStr = properties.getProperty("log" + SUFFIX_LEVEL);
|
||||||
level = JettyLevel.strToLevel(levelStr);
|
level = toJettyLevel("log", levelStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return level != null ? level : DEFAULT_LEVEL;
|
return level != null ? level : DEFAULT_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static JettyLevel toJettyLevel(String loggerName, String levelStr)
|
||||||
|
{
|
||||||
|
if (levelStr == null)
|
||||||
|
return null;
|
||||||
|
JettyLevel level = JettyLevel.strToLevel(levelStr);
|
||||||
|
if (level == null)
|
||||||
|
{
|
||||||
|
System.err.printf("Unknown JettyLogger/Slf4J Level [%s]=[%s], expecting only [%s] as values.",
|
||||||
|
loggerName, levelStr, Stream.of(JettyLevel.values()).map(JettyLevel::toString).collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
public TimeZone getTimeZone(String key)
|
public TimeZone getTimeZone(String key)
|
||||||
{
|
{
|
||||||
String zoneIdStr = properties.getProperty(key);
|
String zoneIdStr = properties.getProperty(key);
|
||||||
|
|
|
@ -24,8 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.slf4j.ILoggerFactory;
|
import org.slf4j.ILoggerFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -164,11 +162,9 @@ public class JettyLoggerFactory implements ILoggerFactory, JettyLoggerFactoryMBe
|
||||||
@Override
|
@Override
|
||||||
public boolean setLoggerLevel(String loggerName, String levelName)
|
public boolean setLoggerLevel(String loggerName, String levelName)
|
||||||
{
|
{
|
||||||
JettyLevel level = JettyLevel.strToLevel(levelName);
|
JettyLevel level = JettyLoggerConfiguration.toJettyLevel(loggerName, levelName);
|
||||||
if (level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
System.err.printf("Unknown JettyLogger/Slf4J Level [%s]=[%s], expecting only [%s] as values.",
|
|
||||||
loggerName, levelName, Stream.of(JettyLevel.values()).map(JettyLevel::toString).collect(Collectors.joining(", ")));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
JettyLogger jettyLogger = getJettyLogger(loggerName);
|
JettyLogger jettyLogger = getJettyLogger(loggerName);
|
||||||
|
|
Loading…
Reference in New Issue