Archive

Posts Tagged ‘Logging’

Singletons

Here’s another little something to keep you entertained while you’re waiting for things to get underway here again (it’ll happen eventually, I promise!).

The Happy Singleton

The Happy Singleton

Event Logging Forever

I’ve been working on my event logging class for some time now, indeed remarkably long for something so simple. So, why is that? Well firstly it’s because I want to get it right – logging is a really important feature for helping bug testers provide me with diagnostic information. Secondly, it’s because of all the various stages of design and development and repetition I’ve been through. That’s what I’m going to be talking about today.

So when I started, my log was a class with a single std::ofstream to which you could write lines of text. This gradually gained features: sections and indentation, error reporting, timestamps, multiple output streams, and eventually a message priority system. And I finished the log with these features a long time ago, as part of one of my first attempts at game engine creation.

However, since then I have several times restarted my engine development, whether due to a long period where lots of programming was impossible, or due to the discovery of new libraries. Well right now I think I have basically conceived a log design which need not undergo any more drastic changes.

I have at last decided on the following features:

  • removal of logging at compile time (with macros)
  • support for multiple output streams: files, std::ostreams and custom classes
  • control of log verbosity at runtime globally and per stream
  • printing of messages
  • messages which wait for a response
  • error messages (with message boxes)
  • memory dumps
  • indentation and sections
  • XML logging

There might be one or two extra things, but that’s the general idea. The plan came through a lot of iterations to get there, and there are in fact hidden depths. For example, priorities of messages are just integers, but  priorities of streams have the following form:

typedef unsigned int __Priority;
struct Level {
 __Priority Priority, MaxIndent;
 bool ErrorOnly;
};

Not only do stream priorities (“levels”) have an actual priority value, they also have a maximum number of indentations they allow, and a flag to mark whether they only accept error messages. This immediately makes the concept of which level is ‘higher priority’ than another slightly trickier. Nonetheless I worked it out and abstracted the user from it via operator overloading. Hopefully I’ll be able to show you how I did it when I finally get the change to release my logging code to you!

Follow

Get every new post delivered to your Inbox.

Join 76 other followers