Andrew Herr (JIRA)
2014-10-02 14:50:33 UTC
Andrew Herr created LOG4J2-865:
----------------------------------
Summary: Changing level in LoggerConfig does not change AppenderControl and does not allow messages at new log level to be logged
Key: LOG4J2-865
URL: https://issues.apache.org/jira/browse/LOG4J2-865
Project: Log4j 2
Issue Type: Bug
Components: Appenders, Configurators
Affects Versions: 2.0.2
Environment: Windows7 64bit, Eclipse, Maven
Reporter: Andrew Herr
Fix For: 2.0.2
I am wrapping log4j2 in order to replace the logging backend used in house, so I am configuring the logger and appenders at runtime with calls to the Context, Configuration, and LoggerConfig. I'd like to change the log level on the fly, so I get the LoggerConfig for my named logger and call setLevel(Level) on it, and then updateLoggers in the context. New messages at the new (less severe) level are not logged. Through a debug session, I can see that the level in LoggerConfig is correctly updated, but the AppenderControl still has the old level, so callAppenders denies my event from being logged.
Code:
Set up the logger + RollingFileAppender
name = logName;
level = logLevel;
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = new LoggerConfig(name, level, false);
PatternLayout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, config, null, null, true, false, null, null);
OnStartupTriggeringPolicy startupTrigger = OnStartupTriggeringPolicy.createPolicy();
SizeBasedTriggeringPolicy sizeTrigger = SizeBasedTriggeringPolicy.createPolicy("25MB");
TriggeringPolicy triggerPolicy = CompositeTriggeringPolicy.createPolicy(startupTrigger, sizeTrigger);
DefaultRolloverStrategy rolloverStrategy = DefaultRolloverStrategy.createStrategy("5", "1", "min", null, config);
RollingFileAppender rollingFileAppender = RollingFileAppender.createAppender(name + ".log", name + ".log.%i", "true", "RollingFile",
"true", "8192", "true", triggerPolicy, rolloverStrategy, layout, null, "true", "false", null, config);
rollingFileAppender.start();
loggerConfig.addAppender(rollingFileAppender, level, null);
config.addLogger(name, loggerConfig);
ctx.updateLoggers();
update the level:
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(name);
loggerConfig.setLevel(logLevel);
ctx.updateLoggers();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
----------------------------------
Summary: Changing level in LoggerConfig does not change AppenderControl and does not allow messages at new log level to be logged
Key: LOG4J2-865
URL: https://issues.apache.org/jira/browse/LOG4J2-865
Project: Log4j 2
Issue Type: Bug
Components: Appenders, Configurators
Affects Versions: 2.0.2
Environment: Windows7 64bit, Eclipse, Maven
Reporter: Andrew Herr
Fix For: 2.0.2
I am wrapping log4j2 in order to replace the logging backend used in house, so I am configuring the logger and appenders at runtime with calls to the Context, Configuration, and LoggerConfig. I'd like to change the log level on the fly, so I get the LoggerConfig for my named logger and call setLevel(Level) on it, and then updateLoggers in the context. New messages at the new (less severe) level are not logged. Through a debug session, I can see that the level in LoggerConfig is correctly updated, but the AppenderControl still has the old level, so callAppenders denies my event from being logged.
Code:
Set up the logger + RollingFileAppender
name = logName;
level = logLevel;
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = new LoggerConfig(name, level, false);
PatternLayout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, config, null, null, true, false, null, null);
OnStartupTriggeringPolicy startupTrigger = OnStartupTriggeringPolicy.createPolicy();
SizeBasedTriggeringPolicy sizeTrigger = SizeBasedTriggeringPolicy.createPolicy("25MB");
TriggeringPolicy triggerPolicy = CompositeTriggeringPolicy.createPolicy(startupTrigger, sizeTrigger);
DefaultRolloverStrategy rolloverStrategy = DefaultRolloverStrategy.createStrategy("5", "1", "min", null, config);
RollingFileAppender rollingFileAppender = RollingFileAppender.createAppender(name + ".log", name + ".log.%i", "true", "RollingFile",
"true", "8192", "true", triggerPolicy, rolloverStrategy, layout, null, "true", "false", null, config);
rollingFileAppender.start();
loggerConfig.addAppender(rollingFileAppender, level, null);
config.addLogger(name, loggerConfig);
ctx.updateLoggers();
update the level:
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(name);
loggerConfig.setLevel(logLevel);
ctx.updateLoggers();
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)