Boost.Log - 如何配置一个文本水槽后端追加到轮换文件 [英] Boost.Log - how to configure a text sink backend to append to rotated files

查看:1672
本文介绍了Boost.Log - 如何配置一个文本水槽后端追加到轮换文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个汇:: text_file_backend 下沉。说我已经有几个旋转的日志文件:

I have a sinks::text_file_backend sink. Say I already have a few rotated log files:

myLog001.log,myLog002.log等

myLog001.log, myLog002.log and so on

我想水槽保持写入最后旋转的文件 - myLog002.log,追加到其内容,并从那里继续转动

I want the sink to keep writing to the last rotated file - myLog002.log, append to its contents and continue rotation from there on.

我只设法找到关键词:open_mode =追加但这只是附加在现有myLogX文件之上,使他们更大,当然很辛苦的阅读

I have only managed to findkeywords::open_mode = append but this only appends on top of the existing myLogX files, making them larger and of course very hard to read.

可以这样在做Boost.Log?

Can this be done in Boost.Log?

推荐答案

该功能内置于文字水槽,而<一href=\"http://boost-log.sourceforge.net/libs/log/doc/html/log/detailed/sink_backends.html#log.detailed.sink_backends.text_file\">the文档包括一个例子来设置文件名模式和规则在某些尺寸和旋转时间:

That functionality is built in to the text sink, and the documentation includes an example to set the file-name pattern and rules for rotating at certain sizes and times:

// The function registers file sink in the logging library
void init_logging()
{
    boost::shared_ptr< logging::core > core = logging::core::get();

    boost::shared_ptr< sinks::text_file_backend > backend =
        boost::make_shared< sinks::text_file_backend >(
            // file name pattern
            keywords::file_name = "file_%5N.log",
            // rotate the file upon reaching 5 MiB size...
            keywords::rotation_size = 5 * 1024 * 1024,
            // ...or at noon, whichever comes first
            keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0)
        );

    // Wrap it into the frontend and register in the core.
    // The backend requires synchronization in the frontend.
    typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t;
    boost::shared_ptr< sink_t > sink(new sink_t(backend));

    core->add_sink(sink);
}

有显然是没有办法使图书馆附加到现有文件与此设置。你应该叫 backend-&GT; scan_for_files(); 前建设,根据管理如图所示旋转文件在文档中标题下,但只有$ p $从覆盖previous日志pvents图书馆它们到期清理之前。

There is apparently no way to make the library append to existing files with this setup. You should call backend->scan_for_files(); prior to constructing sink, as shown under the "Managing rotated files" heading in the documentation, but that only prevents the library from overwriting previous logs before they're due for cleanup.

在本主题中2013年2月开发邮件列表中出现,图书馆的作者解释说,增加了对附加的支持将是一个平凡的变化可能不是目前的设计下进行。

When this topic arose on a development mailing list in February 2013, the library's author explained that adding support for appending would be a nontrivial change that couldn't be made under the current design.

这篇关于Boost.Log - 如何配置一个文本水槽后端追加到轮换文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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