1

I'm using Log4qt and I followed the official steps to configure a log file. I want to know if it's possible to change the configuration dynamically during runtime. Suppose the default file is "myapp.log"

// Set logging level for Log4Qt to TRACE
s.beginGroup("Log4Qt");
s.setValue("Debug", "TRACE");

// Configure logging to log to the file C:/myapp.log using the level TRACE
s.beginGroup("Properties");
s.setValue("log4j.appender.A1", "org.apache.log4j.FileAppender");
s.setValue("log4j.appender.A1.file", "C:/myapp.log");
s.setValue("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout");
s.setValue("log4j.appender.A1.layout.DateFormat", "ISO8601");
s.setValue("log4j.rootLogger", "TRACE, A1");

// Log first message, which initialises Log4Qt
Log4Qt::Logger::logger("MyApplication")->info("Hello World");

And I want to change the filename during runtime, something like this?

QSettings s;
s.beginGroup("Properties");
s.setValue("log4j.appender.A1.file", "C:/NewFile.log");

// Log first message, into new file
Log4Qt::Logger::logger("MyApplication")->info("Hello World");
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
arthur86
  • 531
  • 1
  • 3
  • 20

1 Answers1

2

It looks like after you change your QSettings, and they are reflected there, you need to use:

Log4Qt::Properties::load()

or

Log4Qt::PropertyConfigurator::configure()

with a reference to your QSettings variable. If that doesn't apply the filename change, you may need to look for a way to run startup on the Log4Qt singleton.

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80
  • I used Log4Qt::PropertyConfigurator::configure() because i don't have Properties class. It works correctly. Thanks so much. – arthur86 Dec 17 '12 at 23:05