I'm trying to setup logging using Boost.Log (v1.55.0) and I can't seem to find a way to setup the file collector on the backend so it will only maintain 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"
)
);
In the call to sinks::file::make_collector there are a number of keywords I have found like max_size and min_free_space, but both of those are not what I'm looking for. I just want something like max_files so I can tell it to only keep the last 20 logs, regardless of how much disk space they are taking up. The only reference I could find to something like this was this ticket that was opened: https://svn.boost.org/trac/boost/ticket/8746.
There also doesn't seem to be a documented list of keywords that are available to be used. All of the ones I have found have been from examples found on the net.
It is thread-safe regardless of the kind of loggers you use.
Boost. Log provides the ability to filter log events based on the severity of the log record.
Because most log files are recorded in plain text, the use of any text editor will do just fine to open it. By default, Windows will use Notepad to open a LOG file when you double-click on it.
From the documentation of make_collector
, taken from text_file_backend.hpp:
The following named parameters are supported:
- target - Specifies the target directory for the files being stored in. This parameter is mandatory.
- max_size - Specifies the maximum total size, in bytes, of stored files that the collector will try not to exceed. If the size exceeds this threshold the oldest file(s) is deleted to free space. Note that the threshold may be exceeded if the size of individual files exceed the \c max_size value. The threshold is not maintained, if not specified.
- min_free_space - Specifies the minimum free space, in bytes, in the target directory that the collector tries to maintain. If the threshold is exceeded, the oldest file(s) is deleted to free space. The threshold is not maintained, if not specified.
So boost::log currently does not support collecting old log files based on their number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With