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

C++Logging

C++ Problem Overview


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).

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++ Solutions


Solution 1 - C++

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.

  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.

In my opinion you should go with boost.

Solution 2 - C++

Pantheios is 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 article about a related library explaining why printf()/iostream-based libraries are not type-safe)

Solution 3 - C++

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).

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.

Solution 4 - C++

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.

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.

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

Solution 5 - C++

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::RLogInit(argc, argv);
rlog::StdioNode slog (2, rlog::StdioNode::OutputColor);
slog.subscribeTo( RLOG_CHANNEL("error") );

The second argument to StdioNode is 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.

Solution 6 - C++

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.

Solution 7 - C++

Poco has nice logging support...

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

Solution 8 - C++

maybe http://pantheios.sourceforge.net/">pantheios</a>
though I don't know if it's thread-safe or not...

Solution 9 - C++

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncppalphadevView Question on Stackoverflow
Solution 1 - C++kirsche40View Answer on Stackoverflow
Solution 2 - C++dcwView Answer on Stackoverflow
Solution 3 - C++user54700View Answer on Stackoverflow
Solution 4 - C++johnwbyrdView Answer on Stackoverflow
Solution 5 - C++cassavaView Answer on Stackoverflow
Solution 6 - C++user3458View Answer on Stackoverflow
Solution 7 - C++asitdhalView Answer on Stackoverflow
Solution 8 - C++mhdView Answer on Stackoverflow
Solution 9 - C++user2538508View Answer on Stackoverflow