什么是最有效的线程安全 C++ 记录器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/439791/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:21:33  来源:igfitidea点击:

What is the most efficient thread-safe C++ logger?

c++logging

提问by cppalphadev

I am working on a performance critical multi-threaded application. I looked at rlog, Ace and Boost logging. I chose rlog because I read it was the fastest (when logging is disabled, it has the least overhead).

我正在开发一个性能关键的多线程应用程序。我查看了 rlog、Ace 和 Boost 日志记录。我选择 rlog 是因为我读它是最快的(当禁用日志记录时,它的开销最少)。

The problem I have is it shows the file name, line number etc. even in release mode. If you can tell me how to shut that information off, my problem might be solved. In any case what is the most efficient logger in C++ for my situation?

我遇到的问题是即使在发布模式下它也会显示文件名、行号等。如果你能告诉我如何关闭这些信息,我的问题可能就解决了。无论如何,对于我的情况,C++ 中最有效的记录器是什么?

回答by kirsche40

Unfortunately I am not able down vote at the moment. As far as I can say never ever use crap like Apache log4cxx. It contains serious bugs.

不幸的是,我目前无法拒绝投票。据我所知,永远不要使用像 Apache log4cxx 这样的垃圾。它包含严重的错误。

  1. The last release of 0.9 branch is 0.9.7 and still contains memory leaks because every class with virtual members has no virtual dtor.
  2. The newest release 0.10.x lost a lot of functionality from 0.9.x and is not backwards compatible. You are forced to rewrite a lot of your own code.
  3. The whole project seems to be unmaintained. The release of 0.11.xx has been announced for 2 years.
  1. 0.9 分支的最后一个版本是 0.9.7 并且仍然包含内存泄漏,因为每个具有虚拟成员的类都没有虚拟 dtor。
  2. 最新版本 0.10.x 失去了 0.9.x 的许多功能,并且不向后兼容。您被迫重写大量自己的代码。
  3. 整个项目似乎没有维护。0.11.xx 的发布已经发布了 2 年。

In my opinion you should go with boost.

在我看来,你应该使用 boost。

回答by dcw

Pantheiosis thought to be the best performing C++ logging library, as well as claiming to be the only one that is 100% type-safe (see this articleabout a related library explaining why printf()/iostream-based libraries are not type-safe)

Pantheios被认为是性能最好的C++ 日志库,并且声称是唯一一个 100% 类型安全的库(请参阅这篇关于相关库的文章,解释为什么基于 printf()/iostream 的库不是类型-安全的)

回答by user54700

I've had success with log4cxx at http://logging.apache.org/log4cxx/index.html. It's a C++ version of the popular Log4j logger, is easy to configure either via a conf file or in the code. The overhead when it is disabled is minimal (method call and integer compare).

我在http://logging.apache.org/log4cxx/index.html 上使用 log4cxx 取得了成功。它是流行的 Log4j 记录器的 C++ 版本,易于通过 conf 文件或代码进行配置。禁用时的开销很小(方法调用和整数比较)。

The pattern for the output to the log is defined by a conversion pattern that can be as simple as the date/time and a message. It also handles file size limitation, rollover, etc. You can also configure different patterns for various errors and sources.

输出到日志的模式由转换模式定义,该模式可以像日期/时间和消息一样简单。它还处理文件大小限制、翻转等。您还可以为各种错误和来源配置不同的模式。

回答by johnwbyrd

You may wish to consider the logog system. logog offers exactly this kind of functionality but it does not have the implicit code dependencies that Pantheios has. logog is thread safe and it allows a high degree of control over what types of messages are logged at any point.

您可能希望考虑徽标系统。logog 恰好提供了这种功能,但它没有 Pantheios 具有的隐式代码依赖项。logog 是线程安全的,它允许高度控制在任何时候记录的消息类型。

I'm logog's author and maintainer, so my opinion is a bit biased. But I did review rlog, Pantheios and other logging systems before implementing this one.

我是 logog 的作者和维护者,所以我的观点有点偏颇。但在实施这个系统之前,我确实查看了 rlog、Pantheios 和其他日志系统。

https://github.com/johnwbyrd/logog.

https://github.com/johnwbyrd/logog

回答by cassava

Here is how you could shut off the extra information that rlog gives (such as filename, line number etc.). When you initialize rlog in your main()function (or whereever), you might do the following:

以下是关闭 rlog 提供的额外信息(例如文件名、行号等)的方法。当您在您的main()函数(或任何地方)中初始化 rlog 时,您可能会执行以下操作:

rlog::RLogInit(argc, argv);
rlog::StdioNode slog (2, rlog::StdioNode::OutputColor);
slog.subscribeTo( RLOG_CHANNEL("error") );

The second argument to StdioNodeis for flags to control the output. Check the rlog documentation (can be generated with Doxygen) for the whole list of possible flags. The one in the example here makes rlog only color the output according to severity, without any other information added.

的第二个参数StdioNode是用于控制输出的标志。检查 rlog 文档(可以使用 Doxygen 生成)以获取可能标志的完整列表。此处示例中的一个使 rlog 仅根据严重性为输出着色,不添加任何其他信息。

回答by cassava

Some of the overhead may happen in your macros/streams. You need to be very careful not to compose the string being logged when the logging is disabled.

一些开销可能发生在您的宏/流中。您需要非常小心,不要在禁用日志记录时编写正在记录的字符串。

Clever use of streams and ?: operator allows you to do that, as do macros.

巧妙地使用流和 ?: 运算符允许您这样做,宏也是如此。

回答by Bhai

Poco has nice logging support...

Poco 有很好的日志记录支持......

http://pocoproject.org/slides/110-Logging.pdf

http://pocoproject.org/slides/110-Logging.pdf

回答by user2538508

try out the the c-log lib, https://github.com/0xmalloc/c-log, a fast ,stable and thread-safe log lib for C/C++ language.

试用 c-log 库,https://github.com/0xmalloc/c-log,这是一个用于 C/C++ 语言的快速、稳定和线程安全的日志库。

回答by mhd

maybe pantheios
though I don't know if it's thread-safe or not...

也许pantheios
虽然我不知道它是否是线程安全的...