2

I have complete the simple configuration of Log4j2 latest version library(with log4j2.xml configuration file) which working fine.

Now i want to update/reset configuration whenever the update event fire i as check on internet there is no such API available in the latest version on log4j2 jar.e.g. in old api there is method called

   LogManager.resetConfiguration()

So how i can reset the configuration or refresh log4j2 configuration runtime?

  • Maybe [this](http://stackoverflow.com/questions/14862770/log4j2-assigning-file-appender-filename-at-runtime) helps. – Jens Feb 27 '15 at 11:11

2 Answers2

7

Log4j 2 allows you to specify a monitorInterval. Log4j will check to see if the configuration file has been modified after the number of seconds specified in the monitorInterval have passed. If your file has changed it will be reloaded.

If you do not want to use the automatic method then you need to get the LoggerContext (part of the internal part of Log4j) and call its reconfigure method.

final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); ctx.reconfigure();

rgoers
  • 8,696
  • 1
  • 22
  • 24
  • the automatic method can be configured directly from the xml conf file, this way : `` to check the file every two seconds – Thierry Jun 06 '18 at 12:51
0

I'm not sure if it reloads the configuration from file, but you could try

LogManager.getContext(false).updateLoggers();
rewolf
  • 5,561
  • 4
  • 40
  • 51