[logback-user] Log file path set at runtime

fudmail fudmail at gmail.com
Thu Aug 5 17:29:03 CEST 2010

I believe my logback configuration issue should be common but I am
unable to find a satisfactory resolution.

I'll first describe what I'm trying to achieve.

I have a simple application that is deployed somewhere on the file
system as follows:

|- bin
   |- myExecJar.jar
|- lib
|- conf
   |- logback.xml
|- logs

At runtime my application computes the absolute path of the MyApp
directory (e.g., /home/user1/apps/MyApp) using reflection. A system
property called "app.base.path" is set to this computed path.

This path is computed so that some other misc. paths are resolved
relative to the value of "app.base.path" and are independent of the
working directory (i.e., the value of the "user.dir" property) that
the application was started from.

In my logback.xml configuration file I have the line
to specify where the log file will be written to.

My problem is this. Upon running "java -jar myExecJar.jar", the
logback.xml file is read from the classpath (set in the jar manifest)
and processed before my code gets the chance to programmatically set
the "app.base.path" property. I therefore end up with a directory
being created as follows

Any suggestions on the best way to achieve what I'm trying to do in logback?

Thank you.

More information about the Logback-user mailing list