Am 29.09.2017 um 16:28 schrieb Christopher Schultz:
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
Chris,
thanks for your suggestion.
It must be guaranteed that no log events are lost during this
reconfiguration phase while the dynamic appenders are added again.
And logfiles must not be rolled automatically.
I thought it would help to have kind of different configuration
contexts/spaces.
E.g. if the filebased context is reloaded due to a change, other
(programmatically created) contexts are not touched.
BTW this use case works with log4j1.2.17 and the PropertyWatchdog.
Therefore I hope that this is also supported with log4j2.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]