How log4j log file name or path can be changed at runtime
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Evlogi_Georgiev
Posted On:   Thursday, October 20, 2005 09:25 AM

How log4j log file name or path can be changed at runtime? Let's say if log4j has been initialized using: PropertyConfigurator.configure(log4jConfigFile); How later, in the runtime, the supplied filename to specific appender can be changed from the java code inside the application using log4j. Example: 1) in log4jConfigFile we had: # file log log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=/home/mylogs/mylogfile.log log4j.appender.R.MaxFileSize=1000KB 2) log4j was initialized with PropertyConfigurator.configure(log4jConfigFile); 3) now we want t   More>>

How log4j log file name or path can be changed at runtime?

Let's say if log4j has been initialized using:



PropertyConfigurator.configure(log4jConfigFile);



How later, in the runtime, the supplied filename to specific appender can be changed from the java code inside the application using log4j.

Example:

1) in log4jConfigFile we had:

# file log

log4j.appender.R=org.apache.log4j.RollingFileAppender

log4j.appender.R.File=/home/mylogs/mylogfile.log

log4j.appender.R.MaxFileSize=1000KB



2) log4j was initialized with

PropertyConfigurator.configure(log4jConfigFile);



3) now we want to re-direct the log to file /home/hislogs/mylogfile.log

   <<Less

Re: How log4j log file name or path can be changed at runtime

Posted By:   Pallavi001  
Posted On:   Friday, September 13, 2013 02:41 AM

Hi    Evlogi_Georgiev ,
Your solution worked for me. Thanks for the post!

import org.apache.log4j.DailyRollingFileAppender;

DailyRollingFileAppender loggerAppender=(DailyRollingFileAppender) m_log4jLogger.getAppender("Logger");
loggerAppender.setFile(s_path + File.separator + "Activity.log");
//loggerAppender.setFile("C:\\Activity.log");
loggerAppender.activateOptions(); 

Re: How log4j log file name or path can be changed at runtime

Posted By:   Evlogi_Georgiev  
Posted On:   Thursday, October 20, 2005 11:04 AM

... talking to me :)



RollingFileAppender appndr=logger.getAppender("R");

appndr.setFile("/path/filename.log");

appndr.activateOptions();
About | Sitemap | Contact