Nitin Murlidhar Gaikwad
Nitin Murlidhar Gaikwad

Reputation: 1129

Reload the Log4j.xml file configuration on event occurance

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?

Upvotes: 2

Views: 2091

Answers (2)

rgoers
rgoers

Reputation: 9151

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();

Upvotes: 7

rewolf
rewolf

Reputation: 5891

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

LogManager.getContext(false).updateLoggers();

Upvotes: 0

Related Questions