85

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?

cppalphadev
  • 941
  • 1
  • 8
  • 4
  • 23
    I'm rapidly coming to the conclusion that boost has everything. Even if it doesn't it will have appeared when you look again! – Martin Beckett Jan 13 '09 at 18:58
  • 22
    I can't see why this is closed. He asked a specific and a measurable question. If we neglect what compiler is being used, **there can be only one** "most efficient thread-safe C++ logger". Stackoverflow these days.... – JohnJohn Feb 10 '15 at 21:13
  • 5
    See https://github.com/easylogging/easyloggingpp – phlegx May 12 '15 at 14:40
  • 1
    See also https://github.com/gabime/spdlog – maxik Dec 13 '18 at 05:50

9 Answers9

35

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.

tcdaniel
  • 193
  • 1
  • 1
  • 11
kirsche40
  • 963
  • 1
  • 10
  • 19
  • 10
    "every class with virtual members has no virtual dtor" did not believe it and had to check it. Pretty disappoiting Apache. – ManuelSchneid3r Oct 09 '15 at 18:28
  • 6
    You can downvote now :) – Nic Feb 26 '16 at 17:23
  • 5
    >> "every class with virtual members has no virtual dtor" Whilst this isn't wonderful, it doesn't mean it causes a problem. It's only an issue if the classes are deleted by their dynamic rather than their static type. This, alone, isn't in itself an issue and doesn't mean any memory is leaked. – evilrix Jan 20 '17 at 09:34
  • 2
    @evilrix The classes **have** virtual members but **no** virtual dtor. The classes do not have protected/private new-operators. In fact, this is a very poor and bad code that should never have been released. So what's your point? – kirsche40 Jan 31 '17 at 18:49
  • @kirsche40 I thought my point was pretty clear. Which bit of my explanation of how the standard is worded didn't you understand? Allow me to re-phrase: it's an issue if you attempt to delete via a base class pointer. In that case, if the destructor isn't virtual, the behaviour is undefined. The standard is unusually clear on this point. I'm pretty sure none of what I said implies I'm advocating the OP uses this as an implementation. – evilrix Jul 28 '20 at 12:39
  • @kirsche40 It's 2021! Any better now? – John Oct 04 '21 at 08:58
19

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)

dcw
  • 3,411
  • 2
  • 21
  • 30
  • 4
    And even if they don't like Pantheios, the list of 'competitors' on the page you linked is informative. – jwd Oct 24 '11 at 19:48
10

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.

user54700
  • 109
  • 2
9

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.

cassava
  • 560
  • 6
  • 13
9

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 .

johnwbyrd
  • 3,102
  • 2
  • 27
  • 25
4

Poco has nice logging support...

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

asitdhal
  • 577
  • 2
  • 5
  • 14
4

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.

2

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.

  • 9
    Unfortunately c-log is under GPL, which means you can't use it with non-GPL compatible (e.g. proprietary commercial) software. This makes it unusable for many users. – chris Apr 22 '14 at 10:10
  • now there is no LICENSE in https://github.com/0xmalloc/c-log It's free for commercial and personal use. – user2538508 Aug 27 '14 at 10:22
  • 3
    Are you the author of c-log? If so, I strongly suggest you explicitly state (on the Github page, the readme file and comments in the source code) under which license your software is released. Even if it's meant to be public domain (which I don't recommend!), you should explicitly state that. That being said, there are many "commercial-friendly" (i.e. permissive) open source licenses to choose from - the most popular are Apache, BSD or MIT. – chris Aug 27 '14 at 11:46
  • Linux only? (`#include ` ...) – rustyx Mar 24 '17 at 21:17
2

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

mhd
  • 4,291
  • 10
  • 34
  • 52