0

I'm trying to make a logging system that stores the three previous logs in a directory "stored" and the current one. I'm using the pattern filename_%2N. Everything is working fine, but testing it, the filename integer is never restarted, so after some time, I'm getting files like log_2020.log. Even if I set fileConfig.numFiles to 3, the number goes to N. When this integer is restarted? Is there any way to do it?

boost::shared_ptr<fileSink_t> file(new FileAppender::fileSink_t(
     boost::log::keywords::open_mode = (std::ios::app | std::ios::out),
     boost::log::keywords::file_name = fileConfig.path+fileConfig.filename+"_%2N.log",
     boost::log::keywords::rotation_size = fileConfig.maxSizekb * 1024,
     boost::log::keywords::auto_flush = true
));
file->locked_backend()->set_file_collector(boost::log::sinks::file::make_collector(
    boost::log::keywords::target = fileConfig.path+"/stored",
    boost::log::keywords::max_files = fileConfig.numFiles
));
file->locked_backend()->scan_for_files();
opernas
  • 154
  • 1
  • 10

1 Answers1

0

You can avoid initializing the file counter if you pass false to the update_counter parameter of scan_for_files():

file->locked_backend()->scan_for_files(boost::log::sinks::file::scan_matching, false);

Note that this will create a possibility of file name collision.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27