Logging for fun & profit

Logging for fun & profit

By Igor Roman
Date: Wednesday, 31 August 2005 12:20
Duration: 40 minutes

You can find more information on the speaker's site:

When debugging a problem in an application, people generally resort to scattered print's throughout the code.
Those ad-hoc print's (or even home grown logging systems) sometimes do the trick, but they are not scalable, configurable or in any way manageable for large, complex projects.
I will talk about how to use logging modules to accomplish easier debugging, in particular using Log::Log4perl.
Log4perl is the Perl implementation of the log4j(ava), a logging infrastructure that is really well thought out, in use for years with numerous projects, and available for the major languages.

Log::Log4perl addresses the shortcomings of typical ad-hoc or homegrown logging systems by providing mechanisms to control the amount of data being logged and where it ends up at:
Levels: allow you to specify the priority of log messages. Low-priority messages are suppressed when the configuration allows only higher priority messages.
Categories: define which parts of the system will have logging enabled. Category inheritance allows to elegantly reuse and override previously defined settings on different parts of the category hierarchy.
Appenders: allow to choose which output devices the log data is being output to.

On top of that, Log4perl completely differentiates the logging code from the logging configuration. If you want to add the ability to send an email or write to system messages each time a critical error happens, you only have to add that to the configuration (provided you already have the logging code on place of course).
If you are having problems with some module, you can turn full debug on for it (using only the configuration files), while leaving the rest of the program with the default log level. Later you can restore the default behavior.

Other logging systems exist for Perl, but none that I know of has such a powerful API, but easy to use nonetheless, and available for other languages.

The layout for a 40 min. talk would be:

Easy logging: use Log::Log4perl qw(:easy)

*The whole picture
Configuration: Code configurations vs configuration files
Categories: Inheritance
Appenders: Screen, File, DBI
Layouts: Default and custom layouts

Log::Dispatch: Sending messages to strange places
Performance: How to minimize the impact of logging on performance

Valid XHTML 1.0!   Valid CSS!