How to configure boost.log to limit the number of log files

I am trying to configure logging using Boost.Log (v1.55.0), and I cannot find a way to configure the file collector on the backend, so it will only support the last 20 logs.

namespace sinks     = boost::log::sinks;
namespace keywords  = boost::log::keywords;

typedef sinks::text_file_backend            TextFileBackend;
typedef boost::shared_ptr<TextFileBackend>  TextFileBackendPtr;

TextFileBackendPtr pBackend =
  boost::make_shared<TextFileBackend>
  (
    keywords::file_name = "BoostLogTest_%Y%m%d.log",                            
    keywords::auto_flush = true
  );

// Set up where the rotated files will be stored
pBackend->set_file_collector
(
  sinks::file::make_collector
  (
    keywords::target = "..\\Logs"
  )
);

There are several keywords in the sinks :: file :: make_collector call that I found as max_size and min_free_space, but both of them are not what I am looking for. I just want something like max_files, so I can say that it only stores the last 20 logs, no matter how much disk space they occupy. The only link I could find on something like this was this ticket: https://svn.boost.org/trac/boost/ticket/8746 .

, . , , , .

+4
2

make_collector, text_file_backend.hpp:

:

  • target - , . .
  • max_size - , . , . , , \c max_size. , .
  • min_free_space - , . , . , .

boost:: log .

+5

, 1.61, max_files: http://www.boost.org/doc/libs/1_61_0/libs/log/doc/html/log/detailed/sink_backends.html

void init_file_collecting(boost::shared_ptr< file_sink > sink)
{
    sink->locked_backend()->set_file_collector(sinks::file::make_collector(
        keywords::target = "logs",
        keywords::max_size = 16 * 1024 * 1024,
        keywords::min_free_space = 100 * 1024 * 1024,
        keywords::max_files = 512
    ));
}
+2

All Articles