logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Chicchiriccò <ilgro...@apache.org>
Subject Programmatically set log level in log4j2
Date Mon, 16 Sep 2013 15:51:42 GMT
Hi all,
I am currently using the following code to dynamically update log level 
at runtime, after init:

         LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         LoggerConfig logger = SyncopeConstants.ROOT_LOGGER.equals(name)
                 : ctx.getConfiguration().getLoggerConfig(name);

AFAICT, I can see that the level is actually updated after 
"ctx.updateLoggers()" using the following code (forgive the 
'System.out.println', it's just temporary...):

         for (LoggerConfig logger : 
ctx.getConfiguration().getLoggers().values()) {
             final String loggerName = 
                     ? SyncopeConstants.ROOT_LOGGER : logger.getName();

             System.out.println("Found logger '" + loggerName + "' with 
level " + logger.getLevel());

Unfortunately, the level change is not effective: setting some logger's 
level to DEBUG does not change anything in the log files.
Am I doing something wrong? Thanks for your support.


Francesco Chicchiriccò

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message