javaapache-commons-logging

Apache Commons Logging - How to move configuration file to outside the Jar?


I have a Java application that uses Apache Commons Logging. Currently the config file for this is in src/main/resources/. It runs and logs as I would like. The problem is that this config file gets compiled into the jar file. When it is deployed, this will be an issue. I need to be able to change logging levels etc once deployed. I understand Apache Commons Logging is a "higher level" implementation that actually uses another implementation underneath, in this case it is log4j.

I have tried the following to specify a directory named config which will be at the same level as the jar file:

static {
   System.setProperty("log4j.configuration","./config/log4j.properties");
}
private Log logger = LogFactory.getLog(MyClass.class);

I have also tried:

-Dlog4j.configuration=file://./config/log4j.properties

I have tried several variations of the -D, some with file, some without.

How do I move the configuration file to outside the Jar?


Solution

  • Thank you to John Williams for his direction- it was very helpful in getting me on the right track. It did not fully work. What I ended up doing was the following:

    -Dlog4j.configuration="file:/C:/Path/config/log4j.properties"
    

    Simple- I know- but I was missing the file: in my path.