[sf-perl] Logging: per-object, per-package, kinda-global?

Kevin Goess cpan at goess.org
Sat Apr 6 08:26:02 PDT 2013

> I had the same dilemma with Pinto.  I wanted to log stuff from any and all
> objects, but I didn't want a singleton or global logger.  So I ended up
> passing loggers to all the constructors.  I used a role (called "Loggable")
> to help make each class uniform.  But I never really liked having to pass
> that damn logger object all over the place.
The last couple codebases I've worked on, I've set it up so you can do


and that "Log" class uses AUTOLOAD to catch the method gets the log4perl
logger based on the caller's package something like this

       my $logger = Log::Log4perl::get_logger($caller);
        $logger->$levelname(grep {defined $_ } @args);

That keeps the infrastructure code you have to look at in your own stuff to
a minimum.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20130406/9298218c/attachment.html>

More information about the SanFrancisco-pm mailing list