 So I've just been writing a contender for the most overkill logging system known to man. You see, with my "spare time" projects, I have a tendency to not do anything that doesn't stretch my programming muscles a bit. It's great to do something tricky after watching your skills atrophy for an entire semester. So, when I decide it's time to replace all my cout logging with something a bit tidier, it's not enough to just write them to a file. That would be boring. The task has to become complicated enough to retain my interest.
With that in mind, I based my solution on two articles: Using XML Technologies For Enhancing Log Files and Simple STL Logging System (which is basically about boost streams). By combining these, I end up with an xml logging system which is written to like a standard stream. It's a macro, admittedly, but there's nothing you can do about that while keeping file/function/line information. I have yet to do the xslt part, but most of it is in place, in a rough form.
Along the way, I came up with the idea of a logged exception. A logged exception is basically just a shortcut for logging an error, then throwing an exception, and using the same message for both. This allows the calling code to catch and handle the exception if it wants, but if it is not handled or handled badly then you still have a handy message in the log so you know where things went wrong.
|