初始化后的Boost日志集max_size [英] Boost Log set max_size after initialzation

查看:201
本文介绍了初始化后的Boost日志集max_size的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在后期初始化阶段设置boost log max_size参数. 直到现在,我都可以在初始化阶段像这样设置它:

I'm trying to set the boost log max_size parameter in post initialization stage. until now I was able to set it in the initialization stage like this:

    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(根据输入的值).

Now I want to change the max_size after this call (according to value from input).

我不知道该怎么办

推荐答案

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

The max_size parameter specifies the maximum total size of the rotated files in the target directory. It is a collector parameter, so in order to change it you'll have to create and set a new collector to the file sink returned by 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意味着选择最小的允许值.

Note, however, that the library can only decrease the limit in this way. This is because there is only one collector instance per each target directory so that the limits for the directory are universally maintained throughout the application, even if multiple sinks rotate files into the same directory. make_collector will verify the current limits set for a given target directory and set the most restrictive ones, which for max_size means picking the least allowed value.

这篇关于初始化后的Boost日志集max_size的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆