Search code examples
c++boostboost-log

boost logger doesn't rotate at midnight


logging::wsettings settings;
settings["Core"]["Filter"] = L"%Severity% >= " + level;
settings["Core"]["DisableLogging"] = false;
settings["Sinks.File"]["Destination"] = L"TextFile";
settings["Sinks.File"]["FileName"] = fileName;
settings["Sinks.File"]["Format"] = L"%TimeStamp% %Severity(format=\"%-7s\")% - %Message%";
settings["Sinks.File"]["AutoFlush"] = true;
settings["Sinks.File"]["TimeBasedRotation"] = L"00:00:00";
settings["Sinks.File"]["RotationSize"] = 10 * 1024 * 1024;
settings["Sinks.File"]["Target"] = filePath;
settings["Sinks.File"]["ScanForFiles"] = L"All";
settings["Sinks.File"]["Append"] = true;

auto previousLocale = std::locale::global(boost::locale::generator()(Constants::LOCALE));
logging::init_from_settings(settings);
logging::add_common_attributes();

I can see logs on different days in same log file 'App_2017-05-31.0.log'

2017-05-31 20:07:29.115231 info    -
2017-05-31 20:07:29.115231 info    -  
2017-06-01 01:38:45.139742 error   -  
2017-06-01 03:01:42.303604 error   -  
2017-06-01 19:56:59.995196 info    -  
2017-06-01 19:57:00.385923 info    -  
2017-06-02 01:37:05.281702 error   -  
2017-06-02 02:52:08.488442 error   - 

Do you know how to config logger properly, so it can rotate log files at midnight, and won't have logs on different days in same log file.


Solution

  • There is no TimeBasedRotation parameter. You can set either periodic rotation by setting RotationInterval to the number of seconds between rotations, or RotationTimePoint to the time point at which the rotation happens. The parameters are documented here.