question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add log4j2 annotation processor so packages is not required

See original GitHub issue

Currently it’s necessary to pass the packages attributes via <Configuration packages="io.prometheus.client.log4j2"> in log4j configuration to discover the appender. That means relying on step 5 of https://logging.apache.org/log4j/2.x/manual/plugins.html for appender discovery (analyzing packages and annotations at startup).

It would seem less error prone and more efficient to add the log4j annotation processor to the Maven compiler plugin, so it builds the metadata META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat at build time (step1) ?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fstabcommented, Jan 3, 2022

Thanks for looking into this. So it looks like (2) is not a problem.

However, (1) sounds like this would break existing builds if users create uber-JARs but didn’t configure the log4j-transformer plugin. I imagine fixing the build will be non-trivial in some cases. Many frameworks like Spring inherit the Maven shade plugin from a parent POM, and it is not straightforward where to put the log4j-transformer plugin configuration.

0reactions
rquinio1Acommented, Jan 3, 2022

Good points, here’s what I’ve found:

  1. For uber-jar we’re using this transformer to merge the Log4j2Plugins.dat fields: https://github.com/edwgiz/maven-shaded-log4j-transformer. It’s calling log4j-core APIs to do the merge and dump the resulting file.
  2. log4j2 itself is iterating on all the classloader resources and merging plugins in memory: https://github.com/apache/logging-log4j2/blob/f72100df0decc9bda96b4d769822c4e48b2848fc/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginRegistry.java#L162
Read more comments on GitHub >

github_iconTop Results From Across the Web

Log4j2 (2.1) custom plugin not detected by packages attribute
I am following the solution but not sure how plugin dat file created for custom plugin or where exactly I need to make...
Read more >
Configuring Log4j 2 - Apache Logging Services
Configuration. Inserting log requests into the application code requires a fair amount of planning and effort.
Read more >
Log4j 2 Tutorial: Configuration Example for Logging in Java
Discover how to configure and use appenders, filters, layouts, and levels for logging your ... The not-so-full list of appenders in Log4j 2:....
Read more >
Log4j2 Example Tutorial - Configuration, Levels, Appenders
journaldev is absent and so no logging might have happened at com.journaldev package and the event would be propagated for com and Root....
Read more >
Log4j 2 Plugins - Baeldung
A comma-separated list of packages can be added in the Log4j 2 configuration file. As a prerequisite, annotation processing must be enabled to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found