Reduce the number of journal libraries in a project

The project I'm working on uses several open source frameworks. Each structure uses some kind of logging library. My problem is that the final version contains log4j (in two different versions), slf4j with login and, of course, a general log. I'm looking for a solution, how to reduce the number of libraries, can I exclude the log libraries in the maven pom file and configure slf4j to "catch" logging messages?

+4
source share
3 answers

Slf4j has some information in its guide on how to do this.

I think you want to exclude log4j and commons-logging from all your maven dependencies and load log4j-over-slf4j and jcl-over-slf4j . They are intended to replace log4j and commons-logging and contain the corresponding org.apache.log4j and org.apache.commons.logging classes to replace Logger , Log and friends. This will not reduce libraries, but will cause all log data to be sent via sl4fj . If you do not get rid of the use of these classes (obviously), you cannot reduce the dependency on the slf4j wrapper or the original.

If you want to use a single logging package instead, the correct way to do this is to switch to using commons-logging , which was designed as a delegating log, and then use the slf4j-jcl , which connects to commons-logging .

For descendants, you exclude the dependency in this way for each of the dependencies, which requires log4j .

 <dependency> <groupId>.../groupId> <artifactId>...</artifactId> <version>...</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> 
+3
source

check this

EDIT , read your question a little closer. slf4j adds an outdated bridge for non slf4j projects. But you will still need to supply dependent banks on your path of execution. It’s just worth not repeating that someone else is working.

I mean, you have all those fully qualified characters that essentially need a connection in your jvm. Nothing but some direct voodoo will help you, including dependent libraries.

+2
source

Take a look at pax-logging . It pretty much uses all the interfaces of the logging framework (names and classes of packages on the right, etc.), but it does not implement them. Instead, it associates these facades with the log4j backend.

In other words, your projects continue to use their original logging framework, but they are (transparently) passed to log4j. Thus, your log output is consistent and configured in only one place.

+1
source

Source: https://habr.com/ru/post/1411511/


All Articles