Menu

#262 How do I reload properties while running?

v1.0.4
closed
nobody
None
5
2013-07-14
2011-03-11
No

When my log4cplus configuration file changes, I'd like to reload my logging settings -- reinitialize log4cplus. What's the right way to do it?

I've tried this, but it seems to disable logging completely:
1 Logger::getDefaultHeirarchy.resetConfiguration();
2 log4cplus::helpers::Properties props("logging.properties");
3 props.setProperty("PID", pidstr);
4 PropertyConfigurator propcfg(props, Logger::getDefaultHeirarchy(), PropertyConfigurator::fShadowEnvironment):
5 propcfg.configure();

On the other hand, the follow seems to work for changing log levels, but I don't know if it is complete:
LoggerList loggers = Logger::getRoot()::getCurrentLoggers();
for (LoggerList::iterator it = loggers.begin(); it != loggers.end(); ++it)
{
it->setLogLevel(NOT_SET_LOG_LEVEL);
it->shutdown();
}
followed by lines 2 through 5 above

Thank you.

Discussion

  • Jared Robinson

    Jared Robinson - 2011-03-11
    • status: open --> closed
     
  • Jared Robinson

    Jared Robinson - 2011-03-11

    Never mind. Another person made a code change that broke my reload. Logger::getDefaultHeirarchy.resetConfiguration() does what I expect.

     
  • Václav Haisman

    Václav Haisman - 2013-07-14

    Ticket moved from /p/log4cplus/support-requests/26/

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.