0

I've an application to migrate log4j dependency to log4j2 XML file based with name myAppLog4j.xml

Here is the current loading of log4j,

import org.apache.log4j.xml.DOMConfigurator;

...

public static void loadLog4j(String name) {
   ClassLoader loader = Thread.currentThread().getContextClassLoader();
   DOMConfigurator.configure(loader.getResource(name));
}

Where name argument to the method is the XML file name.

Now I'm using log4j2 2.17.1 which don't have DOM class. Can someone help how to get the same thing accomplished in log4j2.

I don't want to mess with classpath and system properties. Any help is appreciated.

  • Version 2.17.2 reimplemented the `DOMConfigurator` class. – Piotr P. Karwasz Mar 08 '22 at 10:28
  • I didn't see any package with class `DOMConfigurator`. FYI I'm not using any brigde. Just core and api jars. – Jagadeesh Ch Mar 08 '22 at 11:21
  • The support for Log4j 1.x configuration file is in the `log4j-1.2-api` artifact. This will allow you to still use your old XML configuration files. If you wish to switch to a Log4j 2.x configuration, then no code is needed, just place a `log4j2.xml` file on your classpath. – Piotr P. Karwasz Mar 08 '22 at 11:22
  • Ok, so we can not use 1.2 bridge for DOMConfigurator as mentioned in the [limitations here](https://logging.apache.org/log4j/2.x/manual/migration.html#Log4j1.2BridgeLimitations) – Jagadeesh Ch Mar 08 '22 at 11:45
  • +1 for reading the doc, but fortunately that is no longer true (see the [2.17.2](https://logging.apache.org/log4j/2.x/changes-report.html#a2.17.2) changelog). You can send a PR for [this file on github](https://github.com/apache/logging-log4j2/blob/release-2.x/src/site/markdown/manual/migration.md). – Piotr P. Karwasz Mar 08 '22 at 11:54

0 Answers0