-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to merge Log4j2Plugins.dat? #207
Comments
Using a custom jar task without shadowJar and downgrading log4j2 dependencies to 2.0.2 seems to work partly (using jd-gui i see the Log4j2Plugin.dat 3 times instead of only 1 time using the shadowJar method):
The fat jar is able to start and log4j2 is able to find the configuration. Now it fails because it can't find the AsyncAppender
UPDATE: |
You'd need to write your own
The workaround you are using is highly non-performant as you are expanding all of your dependencies onto disk using the |
Thank you @johnrengelman . I don't use zipTree and the code above anymore. It was only for testing another approach. I got it already working with shadowJar using the steps described in my last post. If i get further problems i'll investigate in writing a Transformer. Best regards |
I encountered the same problem (I think) with log4j versions that are greater than 2.5. Downgrading log4j to 2.5 made shadow work again. |
@johnrengelman could you include the converted maven-shaded-log4j-transformer like in this gist? This |
@TheBoegl if someone wants to submit it as PR, I'd be happy to merge it. |
@johnrengelman I think a own plugin would be better to avoid the log4j2 dependency in the shadow plugin, therefore, my previous comment only hints a workaround. |
I created a gradle plugin, but typo'd to reference this issue. |
@TheBoegl neat. No need for it to be a full plugin though. Could just be a library that a user can add to the buildscript classpath. |
@johnrengelman Thanks. It really is just one class that applies this plugin and adds the transformation. I could not think of an easier use case though you seem to have one in mind. Could you please elaborate on that? |
Your library really only needs the transformer class. You don't need a gradle plugin. so you could do this
|
You are absolutely right, hence, I've added the description to the readme. I've thought you meant a much more difficult way... |
For those wanting to merge multiple Log4j2Plugins.dat files and any custom log4j plug-ins using the annotation-generated Log4j2Plugins.dat in an Ant script see the GitHub project MergeLog4j2Plugins. |
In [singlejar](https://github.com/bazelbuild/bazel/tree/master/src/tools/singlejar), add support for combining Log4j2 plugins cache file. Log4j2 plugins are Java annotations collected by a compiler plugin into .dat files for Log4j2 runtime to find them fast. With correct dependency on a `java_plugin`, Bazel already runs the java plugin compiler correctly. The behavior is correct on `bazel run` JAR, but not on `_deploy.jar` fat jars. The silent clobbering of files in general, and the example of these Log4j2 .dat files in particular, is discussed in #7330. - [File structure of Log4j2Plugins.dat files](https://github.com/apache/logging-log4j2/blob/8573ef778d2fad2bbec50a687955dccd2a616cc5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginCache.java) - the test data was generated by a python script, happy to commit it as well - [How to merge Log4j2Plugins.dat?](GradleUp/shadow#207) I tested this fix in my project using Bazel 7.0.2, compiling `//src:java_tools_prebuilt.zip`, and overriding `@remote_java_tools_darwin_arm64` and `@remote_java_tools_linux`. Closes #22581. PiperOrigin-RevId: 704192345 Change-Id: I271f0e4b2db57f5dc24c77ea883c6770f2827ed0
Regarding to this issue https://issues.apache.org/jira/browse/LOG4J2-954 i would like to know how to merge/concat the Log4j2Plugins.dat with shadowJar?
I already tested some configuration patterns but they didn't work.
For maven users there is a workaround like this https://github.com/edwgiz/maven-shaded-log4j-transformer but i could figure out how to get similar working with gradle.
Best regards
The text was updated successfully, but these errors were encountered: