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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to