Boost.Log-记录应用程序的严重错误 [英] Boost.Log - logging an application's critical errors

查看:315
本文介绍了Boost.Log-记录应用程序的严重错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用Boost.log. 如果有多个线程进行大量日志记录,则日志记录操作一定不能锁定,因此我使用此接收器进行日志记录:

I am using Boost.log in my application. Having multiple threads logging massively, a logging operation must not be locking so I log using this sink:

    boost::log::sinks::ordering_asynchronous_sink

进入此前端文件:

    boost::log::sinks::text_file_backend

记录日志的主要目的是查看严重错误以诊断崩溃. 但是我注意到记录只是偶尔偶尔写入一次文件(可能会累加一定数量的记录),这意味着突然崩溃将不会留下任何解释记录的日志记录.

The main purpose of logging is viewing critical errors to diagnose a crash. Yet I've noticed records are being written to file only once in a while (when a certain amount of records has added up probably), which means a sudden crash will leave no log-records explaining it.

我在这里可以做什么?我可以强制在致命严重性错误上写入文件吗?更好的方法?

What can I do here? Can I force file write on Fatal severity errors? A better approach?

推荐答案

听起来您的日志条目没有立即刷新到磁盘.这是提高磁盘性能的典型默认行为(避免进行过多的小写操作),但它有您在此处描述的缺点.您可以在日志记录后端上设置一个auto_flush标志,以确保将所有日志条目立即写入磁盘.有关更多详细信息,请参见 docs .

It sounds like your log entries are not being flushed to disk right away. This is typical default behaviour to improve disk performance (avoiding too many small writes) but it has the downside that you describe here. There is an auto_flush flag that you can set on your logging backend to make sure that all log entries are written to disk right away. See the docs for more details.

这篇关于Boost.Log-记录应用程序的严重错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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