plog
plog copied to clipboard
No documented way to de-initialize
I really like this library. There's only one thing I"m missing though, it doesn't seem to be possible to de-initialize (close/shutdown) a log. Would it be possible to implement this?
Use case, I want a logger to start when the initialize function in my library is used. It is possible to run terminate in my library and than rerun initialize, but from that point on, the logger is printing every single log message twice. So, in my terminate function, I need to shut down the log.
I see. Let me think how to better implement it.
May I ask whether this issue is on your roadmap somewhere?
Oh, it's good you pinged me back.
plog::init is designed for one time initialization and live for the whole app lifetime. In your case you need to use manual logger and appender initialization. For example:
unique_ptr<plog::IAppender> g_appender;
unique_ptr<plog::Logger<PLOG_DEFAULT_INSTANCE>> g_logger;
void init()
{
g_appender.reset(new plog::RollingFileAppender<plog::TxtFormatter>("Hello.txt"));
g_logger.reset(new plog::Logger<PLOG_DEFAULT_INSTANCE>(plog::verbose));
g_logger->addAppender(g_appender.get());
}
void deinit()
{
g_logger.reset();
g_appender.reset();
}
Thus you have full control over the logger lifetime.
Thanks, this works like a charm for me.
Excellent. I leave the issue unresolved until I update the documentation.