I use shadowJar
I use log4j2 and I need to log everything in json format. But once I add 'org.apache.logging.log4j:log4j-layout-template-json:2.17.1'
into build.gradle file I'm getting this errors:
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
if I remove log4j-layout-template-json
dependency usual logging become working, but I need logging in json format using JsonTemplateLayout
.
here is my build.gradle file:
apply plugin: 'java'
apply plugin: "com.github.johnrengelman.shadow"
shadowJar {
zip64 = true
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.apache.logging.log4j:log4j-api:2.17.1'
implementation 'org.apache.logging.log4j:log4j-core:2.17.1'
implementation 'org.apache.logging.log4j:log4j-layout-template-json:2.17.1'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.1'
testImplementation 'org.testng:testng:7.4.0'
}
tasks.named('test') {
// Use TestNG for unit tests.
useTestNG()
}
I also use gradle shadowJar plugin to build fat jar. Because I'm need to run my jar file this way: java -cp example-0.0.1-all.jar org.example.Main
Log4j2PluginsCacheFileTransformer
as suggested in Marian's answer, otherwise the plugins cache from one Log4j's jar overrides the others. – Eskimo