Pregunta

I tried in search of this question, this is my latest requirement.

The question is I need my log files to be created in respective location, and the location is decided in runtime.

I am using following configuration in properties file.

log4j.appender.cabsLoggerCoreRoll=org.apache.log4j.RollingFileAppender  
log4j.appender.cabsLoggerCoreRoll.File=C:/CABS_Exstream/project/svn_code/cabs_ex‌​stream_sai/logs/cabs.log log4j.appender.cabsLoggerCoreRoll.Append = true 
log4j.appender.cabsLoggerCoreRoll.maxBackupIndex=10 
log4j.appender.cabsLoggerCoreRoll.maxFileSize=5MB 
log4j.appender.cabsLoggerCoreRoll.layout=org.apache.log4j.PatternLayout 
log4j.appender.cabsLoggerCoreRoll.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c %x - %m%n`

Could anyone please help to find the solution.

¿Fue útil?

Solución

Try this code snippet to configure your log4j properties file,

          String dynamicLogDir = "C:/CABS_Exstream/project/svn_code/cabs_ex‌​stream_sai/logs";
          System.setProperty("logDir", dynamicLogDir);
          Properties p = new Properties();
          p.load(new FileInputStream("<log4j property file path>\\log4j.properties"));
          PropertyConfigurator.configure( p );

And write your lod4j.properties file likes this;

     log4j.appender.cabsLoggerCoreRoll.File=${logDir}/cabs.log
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top