Using DOMConfigurator.configureAndWatch in case of migrating from Log4j 1.x to 2.x using Log4j 1.x bridge

Viewed 35

According to "Migrating from Log4j 1.x to 2.x" using Log4j 1.x bridge documentation:

Applications can migrate by just using the bridge without further code changes, if they meet the following requirements: They must not configure by calling the Log4j 1.x classes DOMConfigurator

My application uses DOMConfigurator.configureAndWatch().
I just removed log4j1 jars from my application and added log4j2+Log4j 1.x bridge jars.
And I do not see any issues with logging.
Can someone explain what could be wrong with this approach?

1 Answers

The documentation of log4j-1.2-api is not up-to-date and many new features were added in version 2.17.2 (cf. changelog). However not everything is implemented and some methods are no-ops.

In your concrete case DOMConfigurator#configureAndWatch(String) does not actually watch for changes in the file, while the version with an additional long parameter uses the old FileWatchdog that in my experience behaves rather poorly upon shutdown.

A better solution would be to transform your Log4j 1.x XML configuration into a Log4j2 XML configuration and use monitorInterval to request checking the file for updates. Basically "logging through Log4j 1.x, configuration through Log4j2" is a better approach than using the Log4j 1.x "API" for everything.

Related