Shadow World and logging

Every time I start (over) with a MUD server, one of the first bits I do is the logging. Not only because it's easy, but because it's very good to have at an early stage. For the Shadow World server it's no different.

I have made my own loggers most of the time, but targeting multiple logging backends is a lot of work, especially if multi-platform compatibility is wanted. Therefore I have settled on Boost Log for the logging engine to use. It's not yet an official part of Boost, but hopefully will be in the not to distant future. Using Boost Log I will be able to have logging to many destinations at the same time, like the console window, file, Windows system log and the POSIX system log, all depending on run-time configuration.

All logging code will be in the shadow::log namespace, in the src/log.h and src/log.cpp source files.

Now the important thing about logging is that it should be a little intrusive as possible, both from the point of view of the actual code generated, and how it is used. For an example of the first, debug-logging should only be handled if it's actually enabled, if debug-logging is not enabled then the logging statement should (in a perfect world) be a no-op. However unless the logging system is fully implemented using the preprocessor it's going to be impossible to make disabled logging no-ops, but at least a good system will stop as soon as possible.

As for the logging in the Shadow World server, I want it to be as similar to C++ streams as possible. Fortunately Boost Log have good facilities for that, so I don't have to implement my own streams or stream buffers (though it might have been fun). A simple logging line could look something like

log::info << "Starting Shadow World version " << version::tag << '\n';

The output from that, in a console window, could be like

2013-05-09 19:25:32.324 :: info :: Starting Shadow World version 1.0.0


Leave a comment