开发者

Two projects | Two log files

Project1 is using classes from project2 and project3.

Project 2 and开发者_开发百科 project 3 has seperate log4j.properties file and logging classes (Pro2.java & Pro3.java with info,debug methods) in their src folder.

Project1 has a main method that calls

    Pro2.logInfo("This is a log for project2");
    Pro3.logInfo("This is a log for project3");

I want these logs to be logged in two seperate log files as I set in their log4j.properties file.


In general, you can only have one active log4j.properties file (there are exceptions in J2EE environments).

what you want to do, is configure the logging for both projects in a single properties file. You'd need to define two appenders, and specify the categories for each project to use their own appender.


Log4j will automatically look for and use config files it finds on the classpath. It looks for files called log4j.properties and log4j.properties and possibly others.

Alternatively you can programatically load config using;

String filename = "/path/to/config/Project1log4j.properties";
PropertyConfigurator.configure(filename);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜