用C异步线程安全日志记录++ [英] Asynchronous thread-safe logging in C++

查看:235
本文介绍了用C异步线程安全日志记录++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方法可以做到异步和线程安全日志记录在我的C ++项目,如果可能的一个文件。我目前使用 CERR 堵塞的任务,但由于它们是同步的,短期内执行暂停,每次的东西被记录。这是一个相对的图形重应用,所以这种事情是很烦人的。

I'm looking for a way to do asynchronous and thread-safe logging in my C++ project, if possible to one file. I'm currently using cerr and clog for the task, but since they are synchronous, execution shortly pauses every time something is logged. It's a relatively graphics-heavy app, so this kind of thing is quite annoying.

新的记录器应使用异步I / O来摆脱这些停顿。线程安全性也将是可取的,因为我打算尽快增加一些基本的多线程。

The new logger should use asynchronous I/O to get rid of these pauses. Thread-safety would also be desirable as I intend to add some basic multithreading soon.

我认为是一个文件的每个线程的办法,但好像它将使管理日志的噩梦。有什么建议?

I considered a one-file-per-thread approach, but that seemed like it would make managing the logs a nightmare. Any suggestions?

推荐答案

我注意到了这1年及以上旧线。也许异步记录我写的可能是兴趣。

I noticed this 1 year+ old thread. Maybe the asynchronous logger I wrote could be of interest.

<一个href=\"http://www.$c$cproject.com/KB/library/g2log.aspx\">http://www.$c$cproject.com/KB/library/g2log.aspx

G2log使用受保护的消息队列日志条目转发到后台工作,该慢的磁盘访问。

G2log uses a protected message queue to forward log entries to a background worker that the slow disk accesses.

我已经与增加的平均时间为LOG呼叫,但下降的最坏情况下的时间无锁队列试了一下,但是我现在用的是受保护的队列,现在,因为它是跨平台的。它在Windows / Visual Studio 2010和Ubuntu的11.10 / gcc4.6测试。

I have tried it with a lock-free queue which increased the average time for a LOG call but decreased the worst case time, however I am using the protected queue now as it is cross-platform. It's tested on Windows/Visual Studio 2010 and Ubuntu 11.10/gcc4.6.

这是你想要,没有附加条件是什么发布作为公共领域,所以你可以用它做。

It's released as public domain so you can do with it what you want with no strings attached.

这篇关于用C异步线程安全日志记录++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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