gpt4 book ai didi

c++ - Boost Log 初始化后设置 max_size

转载 作者:行者123 更新时间:2023-11-28 05:04:36 30 4
gpt4 key购买 nike

我试图在初始化后阶段设置 boost log max_size 参数。到目前为止,我能够像这样在初始化阶段设置它:

    logging::add_file_log(      
keywords::auto_flush = true,
keywords::target =BOOST_LOG_FOLDER,
keywords::file_name =BOOST_LOG_FILE,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0,0,0),
keywords::rotation_size = 30 * 1024 * 1024,
keywords::max_size = 60 * 1024 * 1024,
);

现在我想在此调用后更改 max_size(根据输入的值)。

我不知道如何做到这一点

最佳答案

max_size 参数指定目标目录中旋转文件的最大总大小。这是一个收集器参数,因此为了更改它,您必须创建一个新的收集器并将其设置为 add_file_log 返回的文件接收器。

typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t;
boost::shared_ptr< sink_t > sink = logging::add_file_log(
keywords::auto_flush = true,
keywords::target =BOOST_LOG_FOLDER,
keywords::file_name =BOOST_LOG_FILE,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0,0,0),
keywords::rotation_size = 30 * 1024 * 1024,
keywords::max_size = 60 * 1024 * 1024,
);

sink->locked_backend()->set_file_collector(
sinks::file::make_collector(
keywords::target =BOOST_LOG_FOLDER,
keywords::max_size = 30 * 1024 * 1024
)
);

但是请注意,图书馆只能通过这种方式降低限制。这是因为每个目标目录只有一个收集器实例,因此即使多个接收器将文件轮换到同一目录中,该目录的限制在整个应用程序中都得到了普遍维护。 make_collector 将验证为给定目标目录设置的当前限制并设置最严格的限制,对于 max_size 意味着选择最小允许值。

关于c++ - Boost Log 初始化后设置 max_size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45129263/

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