Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure log4j logging for a jar?

Tags:

java

log4j

I have a project A with log4j.jar on its build path. I have a number of classes that have logging statements in the form of:

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

I am exporting the project as a jar into another project B. Project B already has its own log4j jar and it's own .xml configuration file. I want to configure particular classes from A to log to Console Apender at varying "levels". How do I do this, please?

like image 481
mvd Avatar asked Aug 29 '12 21:08

mvd


1 Answers

Well, basically, you shouldn't do that. Think of it this way: if that would be done that way, each library that is included in any application would host its own logging configuration, very potentially overriding any of those that are in the application, and each other, in non-specified order. You wouldn't want that. So do not.

[In case you really, really want to do it, you could have properties file in the jar that could be overriden by an xml file in the main application. See details here. But don't. :) ]

like image 57
eis Avatar answered Oct 04 '22 20:10

eis