2009-07-14

Logging modules for perl

I recently decided not to create a logging class of my own, since there must already be a lot out there. Not surprisingly this proved to be a correct decision.

I started looking for packages already available for Ubuntu, and found Log::Handler, Log::Log4perl, and Log::LogLite. I started drafting prototypes for them.



The simplest one to prototype for was LogLite, by far. However, I quickly discarded LogLite for being too simplistic for my needs (which was surprising, as I though I had simplistic needs).

The next one, was Log::Handler, which is easy enough to prototype. Basically, the code block from the synopsis does the 'log to screen' + 'log to file' mantra, and it's almost perfect for me. It has methods for each loglevel ( $logger->info("hello world") ), and takes care of newlines for me. Fits perfectly, so far.

Log::Log4perl was a little more difficult. I had to actually read the whole doc, before I got to get the prototype to work. I was very interested in this log4perl tutorial. It has sections for configuring, appenders and categories, all worth reading. Seems like a hell of a lot to take care, just to spit text to the screen and a file, right? I seemed so at first, but it's not.

I decided to draft a prototype for it anyway. The whole 'change log level on the fly' debugging paradigm got me thinking, it might be useful, it's very interesting, but... it's definitely overkill for my modest needs. Right now, I just want to log to a file, maybe two. It also has nice fatal() methods that throw nice exceptions and die().

That's when I find out, everything I want to do with log4perl (eh, the actual, you know, logging), is actually done by Log::Dispatch. Meh. Forget log4perl, I'll draft a prototype for Dispatch, I though. Another big frustration. No timestamps or log levels by default, just the messages. See? This is why log4perl exists, to make Dispatch useful. Unfortunately, too much work for me.



Summary:
LogLite doesn't provide methods for loglevels, which is both interesting in code aesthetics, and useful should I change the logging backend later.

Log::Handler provides a rather small configuration overhead in order to print log and debug messages to both screen and files, and provide loglevel methods.

Log::Dispatch provides the means for anything and everything, while providing nothing by default.

Log4perl does a lot more than I need, but then, I might want some things I don't need (buyer's remorse). It gives me the impression I might not use most of what it does (like debugging on the fly), and as far as my project is concerned, it's only a frontend to Log::Dispatch. It requires a larger config overhead, has plenty of documentation to catch on, and feels as proper as a canon to kill a rabbit.

Winner: Log::Handler by a full body

Now, on to remove the old bits of debugging 'print' and 'carp' calls that haunt my classes.

No comments:

Post a Comment