Java:- log4j - how to make custom jar package use same log4j settings as main application
Please excuse me if this is a trivial question.
I hav开发者_开发知识库e a main application that uses log4j and there is a GUI interface to change the log level at run time. I can't touch the main application. I am building a package(jar) which simply interfaces the application to an external system. Now I need to have this jar that I am building to use the same log4j settings as the main application that will call the APIs in the jar file i.e. the code in the jar file will have log4j log statements for which the level etc should be picked up from the main application that calls it(this way any runtime change to the log level in the main app will reflect in the jar API log statements as well). And the logs need to go to the same file as the main application's logs.
Thanks in advance.
If your library doesn't modify the logging-level, then the logging behavior of the library will be determined by the main program, i.e., everything should just work correctly.
Follow these instructions for having the main program determine logging for the rest of your package.
Follow these instructions for how to get resources (e.g., property files) associated with the application.
精彩评论