Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://769058]
Approved by wfsp
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-06-26 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (590 votes). Check out past polls.