You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Francesco Chicchiriccò <il...@apache.org> on 2013/09/16 17:51:42 UTC
Programmatically set log level in log4j2
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(LogManager.ROOT_LOGGER_NAME)
: ctx.getConfiguration().getLoggerConfig(name);
logger.setLevel(level);
ctx.updateLoggers();
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 =
LogManager.ROOT_LOGGER_NAME.equals(logger.getName())
? 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.
Regards.
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Programmatically set log level in log4j2
Posted by Francesco Chicchiriccò <il...@apache.org>.
On 16/09/2013 17:51, Francesco Chicchiriccò wrote:
> 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(LogManager.ROOT_LOGGER_NAME)
> : ctx.getConfiguration().getLoggerConfig(name);
> logger.setLevel(level);
> ctx.updateLoggers();
>
> 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 =
> LogManager.ROOT_LOGGER_NAME.equals(logger.getName())
> ? 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.
Hi all,
it seems that yesterday I was making some stupid mistake: I confirm
everything works as expected.
Regards.
--
Francesco Chicchiriccò
ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org