C++ 使用 Boost.Log 日志库的经验?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3510473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Experience using Boost.Log logging library?
提问by amit
I am considering starting to use the Boost.Log logging library. Is anyone using Boost.Log? Please share your experiences in this regard.
我正在考虑开始使用Boost.Log 日志记录库。有人在使用 Boost.Log 吗?请分享您在这方面的经验。
The other libraries I am considering are Apache log4cxx (it seems tedious to install but my team mates want something simple to get started) and Pantheios (the same problem since it works with extra front and back end).
我正在考虑的其他库是 Apache log4cxx(安装起来似乎很乏味,但我的团队成员想要一些简单的入门方法)和 Pantheios(同样的问题,因为它适用于额外的前端和后端)。
回答by Oskar N.
UPDATE: I've since this was written replaced Boost.Log with my own custom logging, mostly because I decided to get rid of all Boost dependencies in all my projects for various reasons. If you are fine with using Boost I guess Boost.Log is still a valid choice judging by Klaim's answer.
更新:自从写这篇文章以来,我用我自己的自定义日志记录替换了 Boost.Log,主要是因为我出于各种原因决定摆脱所有项目中的所有 Boost 依赖项。如果您对使用 Boost 没问题,我猜从Klaim 的回答来看,Boost.Log仍然是一个有效的选择。
My experience with Boost.Log in year 2010 follows.
我在 2010 年使用 Boost.Log 的经验如下。
I've successfully integrated Boost.Log in my game engine and I can only talk good things about it. Sure, it's a little early to use, since version 2 will be the actual version that will become the official Boost.Log.
我已经成功地将 Boost.Log 集成到我的游戏引擎中,我只能谈论它。当然,现在使用还为时过早,因为版本 2 将是将成为官方 Boost.Log 的实际版本。
Beware that the version "1.0" available is not being maintained. To receive updates you must use the bleeding edge (trunk) version which might become unstable. Take this into account if you are going to use this version in any serious projects. If you are not afraid to use bleeding edge versions or future breakage, then go for it. It's really nice to use as it is in its current state.
请注意,可用的版本“1.0”并未得到维护。要接收更新,您必须使用可能变得不稳定的前沿(主干)版本。如果您打算在任何严肃的项目中使用此版本,请考虑到这一点。如果您不害怕使用最前沿的版本或将来会损坏,那就去吧。在当前状态下使用它真的很好。
I've long thought the hierarchical logging system in log4j/log4cxx was superior, but Boost.Log has got me thinking otherwise. Filtering and attributes is way more flexible.
我一直认为 log4j/log4cxx 中的分层日志系统更胜一筹,但 Boost.Log 让我不这么想。过滤和属性更灵活。
The design of sinks separated by frontend/backend makes it really easy to add additional backends. No need to worry about synchronization issues or filtering which is handled by the frontend. The library also comes with lots of backends already, rotational files, console, syslog, Windows event register, etc.
由前端/后端分隔的接收器的设计使得添加额外的后端变得非常容易。无需担心前端处理的同步问题或过滤。该库还带有许多后端,旋转文件、控制台、系统日志、Windows 事件寄存器等。
I have written my own sink backends; one goes to the in-game console and one to a kind of notification system for more serious events. Was easier than I expected, had it up and running in just a few minutes.
我已经编写了自己的接收器后端;一个转到游戏内控制台,另一个转到一种用于更严重事件的通知系统。比我预期的要容易,只需几分钟就可以启动并运行。
Last but not least, the maintainer/developer is really helpful as well. You'll get plenty of help in the project forums. He's fixed two bugs (whereof one major) just this weekend that I reported :-)
最后但并非最不重要的一点是,维护人员/开发人员也非常有帮助。您将在项目论坛中获得大量帮助。就在这个周末,他修复了我报告的两个错误(其中一个主要错误):-)
回答by Klaim
UPDATE: I am using Boost.Log into a game engine system and I am very happy with it. It's fast, thread-safe and very very flexible when you need it.
更新:我正在使用 Boost.Log 进入游戏引擎系统,我对它非常满意。它快速、线程安全并且在您需要时非常灵活。
Boost.Log should be provided with all Boost libraries in a coming release this year (2013).
在今年(2013 年)即将发布的版本中,所有 Boost 库都应提供 Boost.Log。
Boost.Log is made to setup a log system over it. If you read the documentation, you'll see that it's so flexible that any logging system yon can think of can be build with it (like logging on a distant computer).
Boost.Log 用于在其上设置日志系统。如果您阅读文档,您会发现它是如此灵活,以至于您可以想到的任何日志记录系统都可以使用它来构建(例如在远程计算机上登录)。
So, there are macro to ease use in simple projectsbut I think it's the kind of library that is useful mostly to people that really understand logging and want to build a specific architecture for their application.
所以,有一些宏可以在简单的项目中轻松使用,但我认为这是一种对真正了解日志记录并希望为其应用程序构建特定架构的人有用的库。
About performance, I remember that there was problems at the submission that made it slow compared to other (less flexible) logging libraries but as it was a draft and the first release is not out yet I would not bother if you're not coding a time-critical application.
关于性能,我记得与其他(不太灵活的)日志库相比,提交时存在一些问题,这使它变慢,但由于它是草稿,而且第一个版本尚未发布,如果您不编写代码,我不会打扰时间关键的应用程序。
In the end, I think it's simply too "new" to be evaluated "now". There is no other logging library that is as flexible as this one and I'm not sure if a lot of people will feel the need to use it.
最后,我认为它太“新”而不能“现在”进行评估。没有其他日志库像这个库一样灵活,我不确定是否有很多人会觉得有必要使用它。
Update: a recent email exchange with the Boost.Log author result in some data that suggest tat Boost.Log is clearly an excellent alternative for fast logging.
更新:最近与 Boost.Log 作者的电子邮件交流结果表明 tat Boost.Log 显然是快速日志记录的绝佳替代品。
回答by Qortex
I recently looked into implementing a logging system on a project I was starting.
我最近考虑在我开始的一个项目上实现一个日志系统。
I tried log4cxx as you mention it, it is indeed very tedious to install. It took me several hours to get it to compile under VS2012 (with other dependency libraries...), and then it just crashed when I used it in my project. Certainly some weird stuff going on with standard libraries mismatches, but couldn't figure it out.
我试过你说的log4cxx,安装确实很繁琐。我花了几个小时才让它在 VS2012 下编译(使用其他依赖库......),然后当我在我的项目中使用它时它就崩溃了。当然,标准库不匹配会发生一些奇怪的事情,但无法弄清楚。
So I switched to log4cpp which I got up and running in just a few minutes. I find it elegant and lightweight, just what I needed. It has the big advantage of having the same features as the well-known log4j & co. logging systems which might be a real plus for your teamwork (configuration through config file, etc.)
所以我切换到 log4cpp,我在几分钟内就启动并运行了它。我觉得它优雅轻便,正是我所需要的。它具有与著名的 log4j & co. 相同的功能的巨大优势。日志系统可能对您的团队合作有真正的好处(通过配置文件等进行配置)
As far as performance is concerned, it takes one function call to check if the logger is active for the level of the message, then one function call to actually log the data.
就性能而言,需要一次函数调用来检查记录器是否在消息级别处于活动状态,然后需要一次函数调用来实际记录数据。
With a few home-made macros (to add LINE& co. to messages), log4cpp has really proven useful in my project.
使用一些自制的宏(将LINE和 co.添加到消息中),log4cpp 在我的项目中确实很有用。
Unfortunately, I didn't try Boost.Log so can't speak about it, but I hope this feedback will still be useful for you if you choose not to go the Boost.Log way.
不幸的是,我没有尝试 Boost.Log 所以不能谈论它,但我希望如果你选择不采用 Boost.Log 方式,这个反馈仍然对你有用。