I've recently tried to add some logging via Boost log to a small application. However, using log rotation I can't for some reason get it to pick up the correct counter in the logs directory.
For example, if my Logs
directory contains the files Log_000.log
and Log_001.log
I'd expect the logging to start with Log_002.log
but it always starts again from 0.
I'm probably missing something but if anyone can spot something I'd be grateful. Here's my startup code:
void initLogging()
{
boost::log::add_common_attributes();
auto core = boost::log::core::get();
core->add_global_attribute("UTCTimeStamp",boost::log::attributes::utc_clock());
auto x = boost::log::add_file_log(
boost::log::keywords::file_name = "Log_%3N.log",
boost::log::keywords::rotation_size = 2 * 1024, // 2k
boost::log::keywords::target = "Logs",
boost::log::keywords::min_free_space = 30 * 1024 * 1024,
boost::log::keywords::max_size = 20 * 1024, // 20k
boost::log::keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point(boost::gregorian::greg_day(31)),
boost::log::keywords::scan_method = boost::log::sinks::file::scan_matching,
boost::log::keywords::format = "%UTCTimeStamp% (%TimeStamp%) [%ThreadID%]: %Message%",
boost::log::keywords::auto_flush = true
);
auto d = x->locked_backend()->scan_for_files();
}
Many thanks