How to configure log4j logging for jar?

I have a project A with log4j.jar on the way to build it. I have several classes that have log statements in the form:

Logger _log = Logger.getLogger(A.<>.class); ... _log.info("..."); 

I am exporting the project as a jar to another project B. Project B already has its own log4j jar and its own .xml configuration file. I want to configure specific classes from A to enter console Apender at different levels. How can I do this, please?

+6
source share
3 answers

Well, basically, you should not do this. Think of it this way: if this is done this way, each library included in any application will have its own logging configuration, very potentially redefining any of those in the application and each other in an indescribable manner, you would not want this . So do not do this.

[If you really want to do this, you may have a properties file in the bank that can be overridden by an XML file in the main application. See more details. But do not. :)]

+1
source

In general, you do not. In general, you want to have one log4j configuration file. But I assume that you can explicitly load your configuration from your code, as described in the log4j documentation

+1
source

Choose a version of log4j.jar, possibly a newer one. You can use only one version. You need to combine the project management configuration of Project A and Project B. You can do this in the log4j classes at runtime, but do not. Just bite the bullet and combine them once into the original control.

+1
source

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


All Articles