gpt4 book ai didi

c++ - 如何设置 boost.log 来限制日志文件的数量

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:29:19 25 4
gpt4 key购买 nike

我正在尝试使用 Boost.Log (v1.55.0) 设置日志记录,但我似乎找不到在后端设置文件收集器的方法,因此它只会保留最后 20 个日志。

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"
)
);

在调用 sinks::file::make_collector 时,我发现了很多关键字,例如 max_size 和 min_free_space,但这两个都不是我要找的。我只想要像 max_files 这样的东西,这样我就可以告诉它只保留最后 20 个日志,而不管它们占用了多少磁盘空间。我能找到的唯一引用是打开的这张票:https://svn.boost.org/trac/boost/ticket/8746 .

似乎也没有可供使用的关键字的记录列表。我找到的所有示例都来自网络上的示例。

最佳答案

来自 make_collector 的文档,取自 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.

因此 boost::log 目前不支持根据编号收集旧日志文件。

关于c++ - 如何设置 boost.log 来限制日志文件的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21288016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com