You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Tomislav <zi...@gmail.com> on 2006/06/02 11:37:46 UTC

log4j.properties and relative path issues

Hello,

The problem is simple, not sure about the solution.
Here's the thing; I need to define the relative path to configuration file
defined in log4j.properties file. Information in this configuration file is then
used in the custom appender I wrote. It works fine with absolute paths defined
in log4j.properties file, but I'm at a loss as to what to do with this relative
path issue.

If I wasn't clear enough, here's an example of what I have, and what I'd like to
do...

Below is a line in log4j.properties file with current setting for the
configuration file for my custom appender. This is the way with everything
working just fine.

log4j.appender.CUSTOM.configurationFile=C:\\workspace\\conf.file

However, what I'd like to get is something like this

log4j.appender.CUSTOM.configurationFile=conf.file

or 

log4j.appender.CUSTOM.configurationFile=.\\conf.file,

or something similar. 

I've seen some posts, not sure if I got them right though, that in case of use
of relative paths in log4j.properties file there needs to be done some
additional coding in servlets and so on. In my case, unfortunately, this is not
the option.

Thank you,
Tomislav


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: log4j.properties and relative path issues

Posted by Jacob Kjome <ho...@visi.com>.
Relative paths are relative to the directory from which the JVM started.  So, if
you make sure that you put your "conf.file" in the director where you start the
JVM, then you are golden.  However, if you would not like to have this burden,
you can also define a dynamic path using a System property.  For instance...

log4j.appender.CUSTOM.configurationFile=${conf.dir}/conf.file

Then, make sure you set the system property before Log4j gets configured.  You
can either do this on the command line that starts the JVM using something
like...

java MyApp -Dconf.dir=C:/some/dir/path

...or you can perform manual Log4j configuration and set the system variable in
code before calling configure("/path/to/log4j.properties").

BTW, don't bother using double backslashes.  Just use forward slashes.  It's
ready properly under both UNIX and Windows and when using a dynamic path, you
add no platform specifics by utilizing forward slashes.

Jake

Quoting Tomislav <zi...@gmail.com>:

> Hello,
>
> The problem is simple, not sure about the solution.
> Here's the thing; I need to define the relative path to configuration file
> defined in log4j.properties file. Information in this configuration file is
> then
> used in the custom appender I wrote. It works fine with absolute paths
> defined
> in log4j.properties file, but I'm at a loss as to what to do with this
> relative
> path issue.
>
> If I wasn't clear enough, here's an example of what I have, and what I'd like
> to
> do...
>
> Below is a line in log4j.properties file with current setting for the
> configuration file for my custom appender. This is the way with everything
> working just fine.
>
> log4j.appender.CUSTOM.configurationFile=C:\\workspace\\conf.file
>
> However, what I'd like to get is something like this
>
> log4j.appender.CUSTOM.configurationFile=conf.file
>
> or
>
> log4j.appender.CUSTOM.configurationFile=.\\conf.file,
>
> or something similar.
>
> I've seen some posts, not sure if I got them right though, that in case of
> use
> of relative paths in log4j.properties file there needs to be done some
> additional coding in servlets and so on. In my case, unfortunately, this is
> not
> the option.
>
> Thank you,
> Tomislav
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org