logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Walter <peter.wal...@estradis.com>
Subject Re: specify the relative directory to log
Date Wed, 06 May 2009 14:00:48 GMT
Hello Luca,

you can solve this via a system property.

When you specify your log file like this:

log4j.appender.LOGFILE.File=${log4j.logpath}/logfile.log

Log4J replaces ${log4j.logpath} with the system property log4j.logpath 
(at least thats what happens in log4j 1.2.15 when using configuration 
via properties file - I'm not perfectly sure about other versions or XML 
config, but i would guess that to work similar there).

Now you just have to set the system property via

System.setProperty("log4j.logpatch", pathToLog);

in your application _before_ initializing the logging system.
To be sure to set the property before initialization you should not use 
the automatic properties resolution of Log4J but use 
PropertyConfigurator.configure().

Greetings,
Peter

Luca Ferrari schrieb:
> On Wednesday 06 May 2009 03:04:59 pm Marc Farrow's cat walking on the keyboard 
> wrote:
>   
>> I am not sure what the problem is, because the example I posted was totally
>> in the program and not in a properties file.
>>     
>
> Sorry, allow me to explain it better. I've got an application with its log4j 
> configuration file, where there is specified a log directory that is relative. I 
> want to transform such log path absolute, because I could install and run the 
> application from several paths, but I want the logs to be stored always in the 
> same folder. Such folder must be computed the first time the application is 
> started, and therefore I cannot specify such absolute path into the log4j file. 
> That's why I'd like to keep the log4j configuration file with the relative path 
> and transform such path absolute at run-time.
>
> Luca
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>   

******************************************************************************
  Dipl. Inf. (FH) Peter Walter
  Senior Softwareentwickler
  
  e.stradis GmbH
  Alter Postweg 101
  86159 Augsburg

  Tel:  0821 259291-191
  Fax:  0821 259291-110
  Mail: peter.walter@estradis.com
  Web:  http://www.estradis.com

  Rechtsform: GmbH, Sitz Augsburg
  Handelsregister: Augsburg HRB 15752
  Geschaeftsfuehrer: Dr. Jochen Schneider, Dr. Stefan Klein, Karen Schneider
******************************************************************************

Der Inhalt dieser E-Mail ist vertraulich und ausschliesslich fuer den
gewuenschten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, dass
jede Form der Veroeffentlichung, Vervielfaeltigung oder Weitergabe des Inhalts
dieser E-Mail unzulaessig ist. Wir bitten Sie, sich in diesem Fall mit dem
Absender der E-Mail in Verbindung zu setzen. Der Inhalt der E-Mail ist nur
rechtsverbindlich, wenn er unsererseits durch einen Brief entsprechend
bestaetigt wird.


The information contained in this email is confidential and is intended
solely for the desired addressee. Access to this email by anyone else
is unauthorized. If you are not the intended recipient, any form of disclosure,
reproduction, distribution or any action taken or refrained from in reliance
on it, is prohibited. Please notify the sender immediately.
The content of this email is not legally binding unless confirmed by letter.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message