Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

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.

Upvotes: 0

Views: 618

Answers (2)

Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

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);

Upvotes: 1

developmentalinsanity
developmentalinsanity

Reputation: 6229

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.

Upvotes: 2

Related Questions