Wednesday, July 18, 2007

Is Log4cpp new, or has it been abandoned?

Any C++ programmers use Log4cpp? For C# we use Log4net for logging, and when I found that PC SMS used Log4cpp as it's logging framework I just assumed it would be as easy to configure as Log4net.

But Log4net has a very active user community, and the mailing list gets regular visits from the developers Ron and Nicko. No so with Log4cpp.

All I needed was a really simple basic setup to log to a file. Could I find anything? Well, would you find this useful, which says "The configuration file format is undocumented and may change without notice". Ok...

Luckily I found the log4cpp.properties file buried within the tests directory of the log4cpp download, which goes some way to giving the example I needed.

So, if anyone else is searching for the simplest Log4cpp configuration to log to a file, just use this:

log4j.rootCategory=DEBUG, FILE

appender.FILE=org.apache.log4j.FileAppender
appender.FILE.fileName=c:\filename.log
appender.FILE.layout=org.apache.log4j.BasicLayout

And no, that's not a typo, and I haven't cut and paste from the wrong file: Log4cpp uses Log4j stuff in its configuration file.

3 comments:

Anonymous said...

Thanks for the post.

I have been looking for a sample config file for log4cpp. The one you mentioned works for me.

Anonymous said...

This post is kinda dead but, for all it´s worth, it doesn´t really _use_ the log4j reference, it just ignores everything but the actual name of the "classes".
This would also work:
appender.FILE=FileAppender
appender.FILE.fileName=c:\filename.log
appender.FILE.layout=BasicLayout

As would this:
appender.FILE=fruitloops.FileAppender

Anonymous said...

Give this a try (C++ logging)
http://clp.sourceforge.net/