A Guide to hlog

There are two types of logging - realtime and buffered.

Realtime logging does what it says on the tin - entries are instantly appended to the log file. This way if your program crashes you will have a detailed logfile right up until the point at which you crashed. However, all these repeated writes to the hard drive are *very* slow - in the region of 2 to 3 milliseconds per entry on my 5,400 rpm Hard drive.

Buffered logging is much faster - I can manage at least 10 entries per millisecond. Instead of writing directly and instantly to the hard drive, the data is held in memory until either CommitLogBuffer or FreeLoggingContext are called. The downside of this is that if your program crashes you will loose any log entries that are still in the buffer.

Of course, you can combine the best of both - have a buffered log that you commit once per loop or once every ten seconds for non-critical logging.

Rather than simply append events to single log files, this logging unit uses Logging Contexts that can write to several different log files at once. This is particularly useful if you use a seperate debug log and an error log - any events logged to the error log can be automatically added to the debug log as well. This is something I personally do often and I hope that the example makes it clear.