如何配置Boost日志,以进行旋转和追加写入? [英] How to configure boost log, for writing with rotating and appending?

查看:137
本文介绍了如何配置Boost日志,以进行旋转和追加写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置Boost日志,以便通过旋转和追加进行书写?

How to configure boost log, for writing with rotating and appending?

重新启动程序后,请勿清除日志文件.

And after restart program, don't clear log file.

int init_log()
{
    typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
    boost::shared_ptr< file_sink > sink( new file_sink (
       keywords::file_name = "app.log", // only one files
       // keywords::open_mode = (std::ios::out | std::ios::app), // is not append
       keywords::open_mode = (std::ios::out | std::ios::app), // is not rotated
       keywords::rotation_size = 10 * 1024
     ));
}

推荐答案

请尝试一下(关键是使用某些 pattern 添加日志名称,而不是像"app.log"这样固定名称),这将启用flre旋转,并且数据将附加到每个创建的文件中.关于日志清除,只要您未指定自定义file_collector,您的日志就应保持不变:)

Please try this out (the key is adding the log name using some pattern and not fixing its name like "app.log") this will enable flre rotation and the data will be appended to each created file. Regarding the log clearing, as long as you haven't specified custom file_collector, your logs should remain intact :)

typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
boost::shared_ptr< file_sink > sink( new file_sink(
        keywords::file_name     = "app%m%d%Y_%H%M%S_%5N.log",   // file name pattern
        keywords::rotation_size = 10*1024                       // rotation size, in characters
        ));

这篇关于如何配置Boost日志,以进行旋转和追加写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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