logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xavier Outhier <xouth...@yahoo.fr>
Subject Using configuration file and programatically changing configuration?
Date Wed, 14 Aug 2013 14:30:24 GMT
Hi all,

the idea is to have to enable the user to change the config from the UI of the web applications
(without accessing the server).
I would like to know if it is possible to have both a configuration file (automatically reloaded
using monitorInterval)  for Log4J2 for the default usage of the application and the configuration
being modified programatically the fly when investigating issue. How to implement that?
On way could be to write on the fly the configuration file when it is set to be reloaded automatically
but is there an another way that would pause the reading from the config file and use the
API?

I already asked this question on logback mailing list and I got a solution using properties
in the configuration file and this piece of code from java side to force LogBack to reload
the configuration file (that is not modified).
On Java side the code snippet for LogBack is
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.reset();                   
    ContextInitializer ci = newContextInitializer(loggerContext);
    ci.autoConfig();

I've tried with Log4j2:
        Properties p = new Properties(System.getProperties());
        p.setProperty("MyProp", "MyPropValue");
        System.setProperties(p);

        LogManager.resetConfiguration();
but it wasn't effective. What is wrong here?

Thanks,

Xavier.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message