Hello,
I am playing with Log4J using both FileAppender and RollingFileAppender. In
defining the appenders (via a config file), I have a line similiar to:
log4j.appender.MY_Appender1.File=trace.log
My question is how do I make path to trace.log relative? The path will
change based on the environment in which the code executes. For example, the
fulll path in development might be c:\my_project\dev\logs\trace.log. In QA
the path might be /usr/local/my_project/qa/logs/trace.log. In production it
might be /usr/local/my_project/prod/logs/trace.log.
While it is not that difficult to just change the config file, I would
rather not have to put the full path in the config file for each file
appender. The problem exacerbates when I have numerous file appenders
declared in the config file. Each one would need to be different depending
on which environment the code is hosted. Additionally, if I share the config
file with other developers on the project, they will have to modify each
file appender in the config file if their directory structure is different.
What I would really like to do is following:
/********************** config file ********************************/
configDir = /usr/local/my_project/prod/logs/
log4j.category.my_category=INFO, MY_Appender1, MY_Appender2, MY_Appender3,
MY_Appender4, MY_Appender5, MY_Appender6, MY_Appender7
...
log4j.appender.MY_Appender1.File=trace1.log
...
log4j.appender.MY_Appender2.File=trace2.log
...
log4j.appender.MY_Appender3.File=trace3.log
...
log4j.appender.MY_Appender4.File=trace4.log
...
log4j.appender.MY_Appender5.File=trace5.log
...
log4j.appender.MY_Appender6.File=trace6.log
...
log4j.appender.MY_Appender7.File=trace7.log
// other stuff
/************** end of config file *****************************/
/************ Java code *************************************/
PropertyConfigurator.configure("config");
Enumeration appenders = cat.getAllAppenders();
while (appenders.hasMoreElements())
{
Appender = (Appender) appenders.nextElement();
if (Appender instanceOf FileAppender)
{
FileAppender fa = (FileAppender) Appender;
fa.setPath(props.getProperty("configDir"); //
how do I do this
}
}
Thanx,
GK
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]