views:

163

answers:

4

I'm about to implement a logging class in C++ and am trying to decide how to do it. I'm curious to know what kind of different logging implementations there are out there.

For example, I've used logging with "levels" in Python. Where you filter out log events that are lower than a certain threshold. It also includes logging "names" where you can filter out events via a hierarchy, for example "app.apples.*" will not be displayed but "app.bananas.*" will be.

I've had thoughts about using "tags", but unsure of the implementation. I've seen games use "bits" for compactness.

So my questions:

  • What implementations have you created or used before?
  • What do you think the advantages and disadvantages of them are?
+3  A: 

I'd read this post by Jeff Atwood

It's about the overflow of Logging and how to avoid it.

Filip Ekberg
Very interesting article.
Gerald Kaszuba
+1  A: 

There are lots of links on the Log4J wikipedia page.

Doug Currie
+1  A: 

Jeff Atwood had a pretty interesting blog entry about logging. The ultimate message of it was that logging is generally unnecessary (to some extents).

Logging generally doesn't scale well (too much data on high traffic systems).

I think the best point of it is that you generally don't need it. It's easier to trace through your code by hand to understand what values are being assigned to things than it is to sift through lots of log files.

It's just information overload.

Now the same can't be said for single user applications. For things like media encoding or general OS usage, it can be nice to have a log for small apps because debug info is useful (to me) in this situation. If you're burning a DVD and something goes wrong, looking at log info can be very helpful to troubleshoot with if you understand the log output.

I think having a few levels would help for the user, such as:

  • No logs
  • Basic logging for general user feedback
  • Highly technical data for a developer or tech-support person to interpret

Depending on the situation, it may be useful to store ALL log data and only display to the user the basic info, or perhaps giving the option to see all detailed data.

It all depends on the domain.

Dan Herbert
+1  A: 

One of our applications uses Registry entries to dynamically control logging/tracing during production execution.

For example: if (Logger.TraceOptionIsEnabled(TraceOption.PLCF_ShowConfig)) {...whatever

Whe executed at run-time, if registry value PLCF_ShowConfig is true, the call returns true, and whatever is executed.

Quite handy.

cookre