share
Stack OverflowBest logging framework for native C++?
[+103] [15] Jox
[2009-03-30 07:45:27]
[ c++ logging ]
[ http://stackoverflow.com/questions/696321/best-logging-framework-for-native-c ] [DELETED]

I'm looking for logging framework for C++ project. My best shot was log4cxx, but it seems that it's abandoned project, with development stopped ~4 years ago, with only one update in last 4-5 years.

Anything better that log4cxx? (log4c & log4cpp are also totally out-of-date)...

[+45] [2009-03-30 08:47:22] Klaim

Update : Boost.Log has been accepted in Boost [1] under conditions and will be available in a coming release. The current target release would be in the end of 2012.

Update 2: Good informations on Boost.Log can be found in these questions:


Another logging library, Boost.Log [4] (by Andrey Semashev, not Boost.Logging by John Torjo) has been proposed to boost and is currently a work in progress.

From the mailing list :

The archive with the library source code, tests and docs is available in the Vault:

http://tinyurl.com/cm9lum

The online docs are also available on the SourceForge page:

http://boost-log.sourceforge.net

The latest code snapshot can be downloaded from CVS on the SourceForge project page:

http://sourceforge.net/projects/boost-log

The code should be compatible with Boost 1.38. Might also work with 1.37, but I didn't try.

[1] http://lists.boost.org/boost-announce/2010/03/0256.php
[2] http://stackoverflow.com/questions/6076405/what-is-boost-log-how-to-get-it-and-how-to-build-it
[3] http://stackoverflow.com/questions/3510473/experience-using-boost-log-logging-library
[4] http://boost-log.sourceforge.net/

Currently it's not building with the intel compiler under linux sourceforge.net/tracker/… - bua
Well,it's a work in progress I guess. - Klaim
I used this for a project, and was quite pleased with how well it worked, although at times the verbosity was somewhat discouraging. Thankfully there are helper macros and free functions to simplify things, though. - adzm
Yeah and as it was reviewed and the verbisity and necessary macros/shortcuts pointed, the boost-release version should be much better. I just hope it don't kill performance, as I'm working with games... - Klaim
(4) Apparently this library is NOT in boost. It has been withdrawn by the author. - Sardathrion
(6) The one I'm pointing is not Boost::Logging by John Torjo (torjo.com/log2/doc/html/index.html) that indeed have been refused and later abandonned by his author (aparently), but Boost::Log by Andrey Semashev that have been accepted in boost but with conditions (lists.boost.org/boost-announce/2010/03/0256.php) and that, from last news, is targeted at the 1.47.0 release (in few months). - Klaim
if looking to waste 3-4 hours with unsuccessful build, by all means use this library. Otherwise wait till it gets to the boost tree. - C-x C-t
Errata: Boost.Log will not be in 1.47.0 , but in a later release. - Klaim
(1) With boost.log you can really make very custom logging, but requires some time to spend on reading documentation and examining examples. Problems with build were recently resolved...at least some of them. But still you sould build boost, (which takes several hours to compile). Use version from svn trunk https://boost-log.svn.sourceforge.net/svnroot/boost-log. - Yuriy Petrovskiy
1
[+42] [2010-02-24 16:16:28] m_pGladiator

I'm looking also for the same thing. So far I evaluated:

  • log4cplus [1] - nice API, easy build, but memory leaks. The author does not care about the memory leaks and they will not be fixed I guess (see here [2])
  • log4cpp [3] - nice API, easy build, but memory leaks
  • log4cxx [4] - requires a bunch of apache stuff to get build (really annoyng until you build it) and at the end it has memory leaks... It is also very big
  • glog [5] - so far version 0.3.0 - too early. Looks promesing though, but maybe later. It still has memory leaks, but it is small
  • ezlogger [6] - cool nice small logging library. The only one without memory leaks! Unfortunately there are no features like configuration files, rolling logs e.t.c. Just logging, but works. It consists of several HPP files, so you just include them in your project. No need to build the whole world in order to work (Apache should learn from that!). The code looks nice, it has superb documentation, so anybody can extend it with whatever features in no time

I still want to look at Boost [7] and the Pantheios [8], but I think ezlogger will be the tool of choice for me. Did I miss some library here? I'd like to make a complete list if possible.

[1] http://log4cplus.sourceforge.net/index.html
[2] http://sourceforge.net/tracker/?func=detail&aid=2922911&group_id=40830&atid=429073
[3] http://log4cpp.sourceforge.net/
[4] http://logging.apache.org/log4cxx/index.html
[5] http://code.google.com/p/google-glog/
[6] http://axter.com/ezlogger/
[7] http://torjo.com/log2/doc/html/index.html
[8] http://www.pantheios.org/

(12) It should be pointed out that those memory "leaks" for log4cplus are leaks in name, but not practice. - Steve
(11) I consider a memory leak everything that allocates memory and not release it. Calling the operator new in a constructor and having empty corresponding destructor is a memory leak. The fact that the object is instantiated only once (so it leaks once and it is not growing) does not fix the leak. - m_pGladiator
(2) Just watch if you use ezlogger's FUNCTRACKER stuff, it is not multithread safe because of the static my_stack member in ezlogger_output_policy::get_stack. Other macros should be safe or at least they don't use that member. I just got rid of it, you will loose the DISPLAYSTACK functions but if you don't need it it should work. - n1ckp
(1) Thanks n1ck! I actually have to post an update. Later the Pantheios shown the best performance and it was easy to write a custom backend for using it - m_pGladiator
(9) I would agree with @Steve - the allocations you're talking about don't come under the heading 'memory leaks', unless 'memory leak' is defined in a way that misses the point somewhat. In a similar way, the CRT will allocate stuff that you cannot deallocate without exiting the process. Those allocations aren't really memory leaks either. The allocations shouldn't be a 'show-stopper' issue when it comes to deciding whether or not to use the library. - mackenir
(BTW, I'm specifically talking about the allocations in log4cplus). - mackenir
2
[+19] [2009-03-30 11:42:39] Serge

You can take a look at this article [1], it discribes a simple, typesafe, threadsafe, portable logging mechanism.

[1] http://www.ddj.com/cpp/201804215

(1) +1 I implemented a logging system based on this article and was really happy with it. It's intuitive, flexible, low overhead and easy to use. - markh44
Just tried to follow that link and get a blank page. Found another link at drdobbs.com/article/…. Is that the same article? - jschoen
@jschoen Yes, it's the same link. - Serge
Any chance to get the zip file to the source code ? the download link on that page is broken ! - ZeroCool
3
[+17] [2009-03-30 17:49:29] Cwan [ACCEPTED]

Checkout Pantheios [1]. Haven't tried this myself, but have the greatest respect for Matthew Wilson.

[1] http://www.pantheios.org

Pantheios still does not support unicode from what I can tell. Just spent some time evaluating it only to discover I can't use it due to this issue. - Avalanchis
The 4th April 2010 release claims full widestring compatibility - dcw
(2) @Avalanchis: Out of curiosity, under what circumstances do you need Unicode logging support? - Joseph Garvin
(24) @Joseph You are developing in non english language and want native error output? Most of this world is non native english speaking. - RedX
Because of all the positive feedback on Pantheios, I was thrilled to try it. Sadly, it has no support for CMake and additionally it suffers from small bugs - like that the path to STLsoft may not contain whitespace when building on windows. - ThE_-_BliZZarD
4
[+11] [2009-03-30 07:54:25] Thomas Watnedal

The Boost Logging [1] framework seem pretty good. I've used it myself on a "toy project" but I haven't really tried it in a large application.

It was however rejected [2] for inclusion in the official Boost library [3], by the author himself. Thats not because its not a good library, it just didn't fit into the Boost library in its current form.

[1] http://torjo.com/log2/doc/html/index.html
[2] http://lists.boost.org/boost-announce/2005/11/0075.php
[3] http://www.boost.org/

5
[+11] [2009-03-30 11:59:35] yesraaj

Here is a log library from google glog [1]

[1] http://code.google.com/p/google-glog/

6
[+7] [2011-09-10 22:55:09] johnwbyrd

You may wish to consider the logog library. The documentation can be accessed here:

http://www.logog.org

logog has basic multibyte character support, a no-memory-leak policy, a BSD-style license, runs on Windows and POSIX like systems, it's safe in a multithreaded environment, has very complete documentation, supports Unicode output, and maintains a test framework. Additionally, there are no external dependencies in logog beyond that which most modern compilers already provide -- it doesn't need Boost or STLSoft, for example.


This looks like a little gem. Looking forward to giving it a try. - alexr
Boost.Log seems heavy weight. I like logog. - SunLiWei
7
[+6] [2009-03-30 07:51:06] Bill Summers

Have a look at the logging library which has been proposed for the Boost C++ libraries.

See: http://torjo.com/log2/doc/html/index.html


8
[+6] [2009-03-31 13:45:27] fco.javier.sanz

I don't think that log4ccxx is abandoned at all. I am actually using the last release of log4cxx in my current project and it works pretty well. Yo can check it here [1]

[1] http://logging.apache.org/log4cxx/changes-report.html

(1) that link just confirms my state: "only one update in last 4-5 years" - Jox
(3) I think it has just reached a level of stability - there really isn't anything more to add. - Martin Beckett
(2) I think log4cxx tries to follow the lo4java design. Log4java has a 1.3 branch abandoned and another branch 2.0 that is still experimental. Version 1.2 of log4java has been there for while so I guess that without new versions of log4java there won't be new log4cxx - fco.javier.sanz
9
[+6] [2009-06-10 23:20:14] lenkite

Pantheios is great, but no unicode/wchar_t support. Ditto for google-glog. One advantage of google-glog is that if you use gflags for options parsing, it builds upon it so that debug flags are automatically available for your program. But no wchar_t support is bad.

log4cxx requires apache portable runtime.

log4cplus is kinda primitive.

Boost.Log by Andrey Semashev really looks good. I am going to try it out and see how it goes.

I am just hoping that I don't have to end up rolling my own..


Any updates on how Boost.Log worked for you? - Avalanchis
April 2010 release claims full widestring compatibility. - dcw
10
[+6] [2010-05-14 08:48:13] wilx

log4cplus - nice API, easy build, but memory leaks. The author does not care about the memory leaks and they will not be fixed I guess (see here)

What you consider leaks are not leaks. The memory gets destroyed and freed properly, as far as I know, at static variables destruction time. IMHO your leak detector is showing false positives here. If your leak detector has any sort for textual output, please share it, attach it to the bug report.


11
[+1] [2009-03-30 08:00:22] jpoh

I've used NLog [1] in our native C++ projects. Its primarily a .NET logging framework but it does offer a COM interop out of the box (which admittedly doesn't offer full functionality but the source code is available so you can grab the source and roll your own COM interop exposing the functionality that you need).

[1] http://www.nlog-project.org/

the N in NLog is for .Net, not for Native, although it can be used by C++, it still requires .NET at runtime - 赵如飞
12
[+1] [2009-05-13 22:27:59] John K

I don't see why few updates to log4cxx are a bad thing, necessarily. It's working great in my project.


(1) Of course it's not necessarily a bad thing. Thing is we want to use out-of-the box tested logging framework, and log4cxx doesn't even compile in VS2k8 easily. - Jox
(2) Ditto here-- it'd be pretty suite if log4cxx build on many newer compilers without requiring goofy, smack-yourself-in-the-forehead patches. - Rhys Ulerich
(3) As well it can segfault in multithreaded apps (issues.apache.org/jira/browse/LOGCXX-322). This problem has been on the books for a year, with no fix. - rbellamy
13
[+1] [2011-08-12 15:54:23] Omnifarious

Nobody has yet mentioned rlog [1]. I'm not sure how thread safe it is. And there is a lot of ugly macro hackery. But it is very fast to have a logging point that is disabled, and it is pretty flexible in choosing what gets logged at runtime.

[1] http://www.arg0.net/rlog

rlog looks quite interesting. Have you succeeded in logging to a file with it? - Burkhard
@Burkhard: I have. But after looking at rlog and trying it out, I've become disenchanted with it. Unfortunately, I can't remember why. :-/ - Omnifarious
14
[+1] [2011-08-19 11:52:09] dimitri

I've been using log4cplus [1] for some time. Portable and stable.

[1] http://log4cplus.sourceforge.net/

15