Alex Rivera | Logout

Log4j Properties in a Custom Place

Asked 2009-05-17T22:35:40.093
14

I'm using Apache Commons Logging and SLF4J with log4j, but I also want to use the log4j.properties in a custom place like conf/log4.properties. Here is the problem:

If i use

  PropertyConfigurator.configure("conf/log4j.properties");

then my app is tied to log4j and defeats the purpose of having ACL and SLF4J.

What is the best way to configure it without the app ever knowing what the logging implementation is?

Edit
Report

2 Answers

26

I think the easiest thing to do is specify the location of the file using the log4j.configuration system property. Adopting the example in the Log4J manual:

java -Dlog4j.configuration=conf/log4j.properties -classpath ...

I believe that Log4J will find a file named "log4j.properties" anywhere on the classpath, but may be hallucinating. Worth trying, however.

answered 2009-05-17T23:06:18.757
1

You can specify config file location with VM argument

-Dlog4j.configuration="file:/C:/workspace3/local/log4j.properties"

answered 2010-03-05T19:54:22.593

Your Answer