1

How can i configure log4cxx that it will write the logs in a specific directory?

The tutorial site which i have used is from here, i want to use daily rolling logs.

Log4cxx Tutorial

After spending some time googling I have tried adding the following line but it seems not to work, now i would appreciate some help.

<param name ="directory" value = "/var/log/myapp/"/>
Oliver
  • 928
  • 9
  • 25

2 Answers2

2

Log4cxx uses a config file similar to log4j so in the config file have something like

log4j.rootLogger=DEBUG, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/var/log/myapp
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

Then in your code intialize the logging system

log4cxx::PropertyConfigurator::configure("config.props");
rerun
  • 25,014
  • 6
  • 48
  • 78
0

You have to specify the file name with the whole directory path like

 <param name="File" value="/var/log/myapp/logfile" />

below the appender tag. And below your triggerPolicy tag set the param name="DatePattern" as you like.

housemaister
  • 3,918
  • 3
  • 19
  • 13