Strategies for registering application logs from library code?

Where I work, we use Log4j to run web applications. Log4j.jar is at the application level, not at the container level. We use the daily copied application. Our log4j.properties files define appenders based on the name of the application package, so only classes in our application package and below are recorded in our application log file.

In my application, I am expanding our infrastructure with some supporting classes. These classes are not included in the application package because they are not exclusive to my application and will ultimately be included in the banner library for use with other applications. Because of this, my registration applications are not picked up by my application application and therefore are not recorded in the application log files.

I want classes in my bank to register in the application log file using classes. However, if I create an application in my application's log4j properties file based on my classes, I suspect that when several applications use my jar due to the identical class names in the log4j.properties files, only one application log file will receive my jar. and that he will get ALL journal entries from EVERY application using this bank. I think this is the case since we are using the static call Logger.getLogger () to retrieve the logger.

First, I want to know if my fears are valid, if this is true, when several web applications in the same or different containers use my jar at the same time.

I would also like to know if there are β€œboundaries” along which this behavior changes. For example, does this problem exist regardless of whether the log4j.jar is a container at the container level or an application level bank, or is each container running in a separate JVM?

Finally, if so, I would like to know which strategies I should use to overcome the problem.

Thanks in advance!

+6
java logging log4j
source share
2 answers

If log4j.jar is only in the web application, then the logs will remain separate, so each web application should have its own log4j.jar and log4j.properties so that all the logs remain separate.

+2
source share

The problem is that the preferred template for log4j is to use static * configurator methods that are not well suited for application containers.

This article solved this problem for me when I came across it ...

0
source share

All Articles