Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Methods for simple logging from modules

by Anonymous Monk
on Jul 07, 2011 at 07:47 UTC ( #913143=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I must confess that I lived a long time without logging and most modules on CPAN seem to implement no internal logging. I gave Log4Perl a try, but just could not get familiar with its complexity. The approach of lightweight modules like Log::Any and Log::Contextual that separate logger calling one one side, and logger configuration and actual logging on the other, looks more appealing. Log:Any seems to gain popularity, but also Log:Contextual (it's in Task::Kensho). I prefer the calling syntax of the second because the actual method is in a sub:

$log->trace('message pre-calculated'); # Log::Any log_trace {'message only if needed'}; # Log::Contextual

On the other hand Log::Any has almost the best way to include it in your module:

use Log::Any qw($log);

My ideal logger calling module should be included as

use Log::Module; # no more configuration!

Do you know of any actual comparision of logging from Perl modules? Are there other pros and cons if you compare Log::Any and Log::Contextual or do you prefer a third module?

Replies are listed 'Best First'.
Re: Methods for simple logging from modules
by Khen1950fx (Canon) on Jul 07, 2011 at 08:43 UTC
    Log::Simplest seems to be what you're looking for. For example:
    #!/usr/bin/perl use strict; use warnings; use Log::Simplest; exit;

      Log::Simplest has hard coded message writing and is one instance of the vast number of Logging modules on CPAN.

      I only want to create log events. By default these should be ignored, unless logging is explicitly configured. Log::Any and Log::Contextual are both designed this loosely coupled pub/sub model.

Re: Methods for simple logging from modules
by pajout (Curate) on Jul 07, 2011 at 10:29 UTC
    I think it very depends on your exact requirements. I often use my proprietary implementation due to specific requirements in my OO design. In result, it looks like this:

    $self->debug1("Starting action..."); my $res = $self->action(); $self->log("Action result:".$res);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://913143]
Approved by Corion
[holli]: mmh
[holli]: that's strange

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-09-23 11:45 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.