How to properly shadow Log4j Core in Gradle? #2416
-
Hi everyone. I have created a simple java application that uses Log4j and JLine. I have created a 'CustomAppender' appender plugin to make the console work properly with JLine input. If I use annotationProccesor in build.gradle, when I create a jar file (gradle shadowJar), it displays the following error on startup: 2024-03-26T18:25:20.155339Z main ERROR Unrecognized format specifier [d]
2024-03-26T18:25:20.158472400Z main ERROR Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
2024-03-26T18:25:20.159513200Z main ERROR Unrecognized format specifier [thread]
2024-03-26T18:25:20.159513200Z main ERROR Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
2024-03-26T18:25:20.159513200Z main ERROR Unrecognized format specifier [level]
2024-03-26T18:25:20.160044800Z main ERROR Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
2024-03-26T18:25:20.160044800Z main ERROR Unrecognized format specifier [logger]
2024-03-26T18:25:20.160044800Z main ERROR Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
2024-03-26T18:25:20.160559700Z main ERROR Unrecognized format specifier [msg]
2024-03-26T18:25:20.160559700Z main ERROR Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
2024-03-26T18:25:20.160559700Z main ERROR Unrecognized format specifier [n]
2024-03-26T18:25:20.160559700Z main ERROR Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
2024-03-26T18:25:20.170962200Z main ERROR Unrecognized format specifier [d]
2024-03-26T18:25:20.171476300Z main ERROR Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
2024-03-26T18:25:20.171476300Z main ERROR Unrecognized format specifier [thread]
2024-03-26T18:25:20.171476300Z main ERROR Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
2024-03-26T18:25:20.171476300Z main ERROR Unrecognized format specifier [level]
2024-03-26T18:25:20.171992300Z main ERROR Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
2024-03-26T18:25:20.171992300Z main ERROR Unrecognized format specifier [logger]
2024-03-26T18:25:20.171992300Z main ERROR Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
2024-03-26T18:25:20.171992300Z main ERROR Unrecognized format specifier [msg]
2024-03-26T18:25:20.172505200Z main ERROR Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
2024-03-26T18:25:20.172505200Z main ERROR Unrecognized format specifier [n]
2024-03-26T18:25:20.172505200Z main ERROR Unrecognized conversion specifier [n] starting at position 56 in conversion pattern. If I remove annotationProccesor and in log4j2.xml in the configuration tag enter packages="org.example", the program starts working correctly, but displays the following text: 2024-03-26T18:38:02.165679600Z main WARN The use of package scanning to locate plugins is deprecated and will be removed in a future release
2024-03-26T18:38:02.172365200Z main WARN The use of package scanning to locate plugins is deprecated and will be removed in a future release
2024-03-26T18:38:02.173900Z main WARN The use of package scanning to locate plugins is deprecated and will be removed in a future release
2024-03-26T18:38:02.192486400Z main WARN The use of package scanning to locate plugins is deprecated and will be removed in a future release Please help me, what am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You are using the Shadow Gradle plugin to collapse all your application dependencies. By breaking the original packaging of the
|
Beta Was this translation helpful? Give feedback.
@nikita51bot,
The
Log4j2PluginsCacheFileTransformer
seems to be affected by two bugs:Log4j2Plugins.dat
files in your own project, but only those found in JAR files. You can work around this by creating a Gradle sub-project for the appender,Log4j2Plugins.dat
files if there is only one such file (this is similar to apache/logging-log4j-transform#87). This should not be a problem in your case.Edit: I added a comment about these problems to GradleUp/shadow#427