logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Programmatically added loggers lost due to automatic reconfiguration
Date Fri, 29 Sep 2017 14:28:28 GMT
Michael,

On 9/29/17 8:30 AM, Michael Heinen wrote:
> I use Log4j 2.9.1 with the XML configuration. A monitorInterval is
> specified in the XML config in order to reconfigure log4j, e.g. for
> debugging.
> Besides the XML configuration some loggers and appendes are created
> dynamically in Java.
> 
> Problem:
> The dynamically added loggers and appenders are lost after the XML
> configuration has been reloaded.
> 
> <javaCode>
> LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
> Configuration config = ctx.getConfiguration();
> 
> Appender appender = RollingFileAppender.newBuilder()...
> config.addAppender(appender);
> 
> LoggerConfig loggerConfig = LoggerConfig.createLogger(...)
> loggerConfig.addAppender(appender, null, null);
> config.addLogger(loggerName, loggerConfig);
> ctx.updateLoggers();
> <javaCode>
> 
> Could the dynamically added loggers/appenders be isolated from the
> automatic reconfiguration?
> Is there another way to add them programamtically?

Maybe what's called-for here is a framework-triggered event that your
code can subscribe to. When the logger (etc) is reloaded, you get a
notification and can re-enable any custom configuration.

-chris


Mime
View raw message