3

I use a textfile backend for a sink, which contains to placeholder elements

  • date
  • log-rotation counter

"%Y-%m-%d_mylogfile_%3N.log"

Furthermore, the backend is configured to rotate at a certain size and at midnight.

using namespace boost::log;
boost::shared_ptr<sinks::text_file_backend> backend = boost::make_shared<sinks::text_file_backend>(keywords::file_name = "%Y-%m-%d_mylogfile_%3N.log", keywords::rotation_size = 30 * 1024 * 1024, keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),keywords::open_mode = std::ios_base::app);

This works well for programs that not run over midnight. When a program runs for one day, started at noon, I have the following issue:

2017-11-23_mylogfile_000.log
2017-11-23_mylogfile_001.log

// after rotation on midnight
2017-11-24_mylogfile_002.log  // <-- counter does not reset to 000

// after restart of the program at noon
2017-11-24_mylogfile_000.log

The counter does not reset, when the file gets a new name at midnight. When I restart the program at noon, there is a confusing log rotation order.

Question:
Can someone help and tell me how to reset the log-rotation counter, when the date in file name changes, but the program keeps running?

Thank you in advance.

nils
  • 61
  • 4

0 Answers0