It seems like log4j is trying to parse .json config file by XML parser, but why?
I set log4j config file by command line argument:
-Dlog4j.configurationFile=src/log4j2.json
file content:
{
"configuration": {
"appenders": {
"Console": {
"name": "Console",
"target": "SYSTEM_OUT",
"PatternLayout": {
"pattern": "%date %thread %logger %message"
}
}
},
"loggers": {
"root": {
"level": "debug",
"appender-ref": {
"ref": "Console"
}
}
}
}
}
What I get:
[Fatal Error] log4j2.json:1:1: Content is not allowed in prolog.
ERROR StatusLogger Error parsing D:\Dev\HDelphiCrawler\src\log4j2.json org.xml.sax.SAXParseException; systemId: file:///D:/Dev/HDelphiCrawler/src/log4j2.json; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:140)
at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:44)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:410)
....and so on...
ERROR StatusLogger No logging configuration
Jars in my lib folder:
Even though there is already an accepted answer I'll post my solution too. Maybe this helps someone else in the future...
The reason why it didn't work for me was that I didn't have the jackson-core and jackson-databind library available. After I added
compile 'com.fasterxml.jackson.core:jackson-core:2.8.7'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.2'
to my build.gradle file everything worked fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With