tags:

views:

59

answers:

1

Hi,

Please excuse me if this is a trivial question.

I have 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.

A: 

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.

Steve Emmerson
Hi, sorry about the delay in response.. For example - this is how I have it now in my library. At the start of the class:private Logger _logger = Logger.getLogger(this.getClass());Then in the methods I just add debug, warn, info statements. Do I have to have a log4j properties file in my library(Do I have to initialize the logger parameters in my library separately)? I tried without one and added the jar file to the "Bundle-ClassPath" in Manifest.MF but it didn't work. It says appender not found:log4j:WARN No appenders could be found for logger (com.Test.MyTest).Thanks
Infinity