Bring together all legacy logging libraries in third-party dependencies (Java, Maven)

Viewed 110

I’m working on a maven project that has dependencies to large libraries. There are lots of transitive dependencies and they do not follow any conventions. I can not change any source code of the libraries. Let’s simply call them third-party legacy libraries.

What is the best way to do the logging?

My research got me to the conclusion to use either SLF4J API or Log4j2 API. See https://logging.apache.org/log4j/2.0/faq.html#api-tradeoffs

However, I’m not sure how to clean up the mess originating from the third-party libraries.

  • They use all kind of (legacy) Logging Libraries (JUL, Log4j v1, Apache Commons Logging JCL, etc.).
  • Those libraries are used in different versions.

I know that you can Bridge legacy APIs: https://www.slf4j.org/legacy.html But how do I know which bridge I need when there’s such a mess? At the moment, I added the following dependencies:

<dependency> <!-- Facade for logging systems -->
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-api</artifactId>
   <version>2.17.1</version>
</dependency>
<dependency> <!-- actual logging implementation -->
   <groupId>org.apache.logging.log4j</groupId>
   <artifactId>log4j-core</artifactId>
   <version>2.17.1</version>
</dependency>

Logging something in my project is easy:

Logger logger = LogManager.getLogger(ConfigurationService.class)
logger.info("Initializing…");

Is there any easy way to make sure all logging libraries get bridged?

What happens to the logs that don’t get bridged?

Do I need to exclude each and every logging library from each dependency like this?

<dependency>
  <groupId>someGroupId</groupId>
  <artifactId>someArtifact</artifactId>
  <exclusions>
      <exclusion>
        <artifactId>commons-logging</artifactId>
        <groupId>commons-logging</groupId>
      </exclusion>
  </exclusions>
</dependency>

I know that this question is not very specific. But after doing hours of research, I didn't find an easy solution to this problem. I would like to know how you would approach this problem.

0 Answers
Related