Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Is there some standard for logging from within the modules?

by techcode (Hermit)
on Jun 06, 2009 at 11:50 UTC ( #769058=perlquestion: print w/replies, xml ) Need Help??
techcode has asked for the wisdom of the Perl Monks concerning the following question:

I've found many modules used for logging - but is there some standard/recommendation (I've checked "Writing Perl Modules for CPAN", permod/perlmodstyle ...) on how to approach logging from within the modules that you write?

I'm thinking along the lines of allowing the programmer that uses your module, to specify err/info/debug log file names (and/or file handles), and perhaps the level of logging that (s)he wants to appear. Or to disable logging - obviously :)

Or if you know of any good examples of modules that have those implemented, that you can recommend.

Have you tried freelancing/outsourcing? Check out Scriptlance - I work there since 2003. For more info about Scriptlance and freelancing in general check out my home node.
  • Comment on Is there some standard for logging from within the modules?

Replies are listed 'Best First'.
Re: Is there some standard for logging from within the modules?
by almut (Canon) on Jun 06, 2009 at 12:09 UTC

    I don't think some standard has evolved (yet). Presumably because people's preferences vary too much. Sure there's Log::Log4Perl, but I suspect that some consider its extensive configurability overkill for their little logging requirements (or don't like the additional dependency with their modules), and thus don't use it...

      Log::Log4Perl has :easy mode, I think that makes it strong contender for standard :)
Re: Is there some standard for logging from within the modules?
by Sixtease (Friar) on Nov 17, 2009 at 09:31 UTC

    I have just come across the same problem. The way I solved it is that I simply created a log method in my module and I pass the messages to it. The method stores the messages in the object.

    It is fairly easy for users to redefine the method (directly or by subclassing).

    sub log { my ($self, $msg) = @_; push @{ $self->{log} }, { timestamp => time, message => $msg, }; } sub foo { my ($self) = @_; $self->log('Entered foo'); }
    use strict; use warnings; print "Just Another Perl Hacker\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://769058]
Approved by wfsp
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2016-09-26 04:59 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (475 votes). Check out past polls.