Dear LazyPerl, looking for a logger

I'm looking for a logger module like Log::Log4Perl but one I can hand a filename to and be done with it. No /etc configuration files or other crap to deal with, and still have debug/warn/etc log levels.

Any ideas? Something like:

use Log::EasyLog;

my $logger = Log::EasyLog->new( file => '/tmp/mylogfile' );


Try Log::Any::App.

use Log::Any::App '$log', -file => '/tmp/mylogfile';

To set log level from within the script:

use Log::Any::App '$log', -file => '/tmp/mylogfile', -level => 'debug';

To set log level from outside the script, set LOG_LEVEL=debug.

I was recently looking for a logging library with the same criteria and someone pointed me to Log::Dispatch. Check it out ...

You gotta be kiddin' me! :)

Two blog entries ago in this exact blog site I wrote about a logging module... seriously, dude.

Check out Log::Dispatchouli which is a freakin' awesome wrapper around Log::Dispatch. It supports levels, syslog, prefixes, output to files, stdout, stderr, etc.

And if you're using it with Moose/Mouse/etc. MooseX::Role::Loggable might be of value.

Read the blog post:

What is wrong with

use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init( { 
   level   => $DEBUG,
   file    => ">>test.log" 
 } );
DEBUG("Debug this!");
INFO("Info this!");
WARN("Warn this!");
ERROR("Error this!");

taken right from perldoc Log::Log4perl?

If you want, you can get a normal logger after easy_init and use it too:

my $logger = Log::Log4per->get_logger();

I think easy_init() is easy enough and I used to use it a lot.

But since a couple of years ago I started writing most code in modules instead of scripts, and Log::Log4perl complains with "Log4perl: Seems like no initialization happened. Forgot to call init()?". It's also a turn-off for some module users if I use Log4perl inside my modules. So I've been using Log::Any instead.

Leave a comment

About Phred

user-pic I blog about Perl and mod_perl.