Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Methods for simple logging from modules

by Anonymous Monk
on Jul 07, 2011 at 07:47 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://913143]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found