Why not place a temporary Log4j config file in the classspath that does
something minimal like configuring only the root logger and setting the
appender to console with the level set to WARN. Then, when you are ready to
configure at runtime, you can load up your real log4j.properties file and pass
in a properties object containing a property you can reference in
log4j.properties with the path for the log file. For instance...
log4j.appender.LOGFILE.File=${file.appender.path}
Note that you could also use this properties file as your primary Log4j
auto-configuration file and set a system property instead. You'd reference it
the same way as above. For instance...
java -Dfile.appender.path=/path/to/logfile.log MyApplcation
Jake
On Wed, 20 May 2009 06:41:56 -0700 (PDT)
power97 <cjo...@shaw.ca> wrote:
Hi,
I am dynamically setting the File name that log4j is logging to with the
FileAppender. However , to do this I am first setting the file to "nul" and
then in script setting it to the real log name. This works fine in Windows
but when run on Unix it actually creates a file called "nul". I can remove
it with a shell script but I would prefer to not have to do that. Here is my
code and is there a better way to do this ?
log4j.properties
log4j.appender.LOGFILE.File=nul
Code
// Set log file name
FileAppender appender = (FileAppender)logger.getAppender("LOGFILE");
appender.setFile(Filename.generateTimestampFilename(logFolderPath,
strLogFileName, ".log"));
appender.activateOptions();
Second , is there a way to dynamically turn off the FileAppender ?
Thanks In Advance
--
View this message in context:
http://www.nabble.com/Dynamic-File-Name-and-Turn-off-File-Logging-tp23635686p23635686.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org