'Log4j 1.x to Log4j 2 Migration: BasicConfigurator and DOMConfigurator missing
I am migrating a large application from Log4j 1.2.12 to Log4j 2.1.17. After replacing the dependencies in the build.gradle many classes are now showing errors. The official Apache Migration Guide unfortunately doesn't mention the problems I encounter. For your information: I'm doing the option 2 of the guide "Option 2: convert your application to the Log4j 2 API (log4j-api)" (the option 1 bridge is not applicable due to constraints listed in the guide). The following lines of code are being shown as an error:
// [...]
import org.apache.logging.log4j.BasicConfigurator; // ERROR
import org.apache.logging.log4j.ConsoleAppender; // ERROR
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.PropertyConfigurator; // ERROR
import org.apache.logging.log4j.SimpleLayout;
import org.apache.logging.log4j.xml.DOMConfigurator; // ERROR
public class DefaultLogStrategy implements LogStrategy {
// [...]
The guide says just to add logging between apache and log4j (in the import statements). Especially PropertyConfigurator and DOMConfigurator are classes for which I wonder if they are still in Log4j2 and if yes, why their eventual abscence has not been mentioned by the guide.
For the record: I'm aware that you don't need to use DOMConfigurator or BasicConfigurator. Yet I want to keep it unless I absolutely have to make big changes to the code base.
EDIT: A general problem for me is now that I used to have only a single jar file in the project. The migration requires me to have 2 jars (build.gradle files show):
// BEFORE
dependencies {
// [...]
libraryImplementation 'log4j:log4j:1.2.12'
}
// AFTER
dependencies {
// [...]
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
implementation("org.apache.logging.log4j:log4j-core:2.17.1")
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
