Log::Pony - Yet another simple logger class
my $logger = Log::Pony->new( log_level => $ENV{MYAPP_LOG_LEVEL} || 'info', ); $logger->info("Payed by her"); $logger->warn("A unexpected things happend!"); $logger->critical("Ouch! Disk full!"); $logger->debug("Through here...");
Log::Pony is simple logger class.
THIS IS A DEVELOPMENT RELEASE. API MAY CHANGE WITHOUT NOTICE.
Log::Pony provides
I need a simple, flexible, OO-ish, customizable, and thin logger class, but I can't find any module on CPAN.
Create new Log::Pony instance.
Mandatory parameter for this method is log_level. You can on specify the log level by constructor.
Optionaly, you can pass color parameter. It enables colorize for default $logger->process method. You can access this parameters value by $logger->color().
$logger->process
$logger->color()
And other parameters passed to $logger->init(%args) method.
$logger->init(%args)
Get a current log level in string.
Returns color parameter passed at constructor.
This method format log message by sprintf by $format and @args.
And output log by $logger->process($level, $message).
$logger->process($level, $message)
Shorthand for $logger->log('DEBUG', @msg).
$logger->log('DEBUG', @msg)
Shorthand for $logger->log('INFO', @msg).
$logger->log('INFO', @msg)
Shorthand for $logger->log('WARN', @msg).
$logger->log('WARN', @msg)
Shorthand for $logger->log('CRITICAL', @msg).
$logger->log('CRITICAL', @msg)
You can extend this class by inheritance.
You can hook $logger->init(%args).
This method is a hook point to extend your logger class. Default implementation of this method does no operation.
Here is an example code:
pckage My::Logger; use parent qw/Log::Pony/; sub init { my ($self, %args) = @_; my $rotate_logs = File::RotateLogs->new( %args ); $self->{rotate_logs} = $rotate_logs; } sub process { my ($self, $level, $message) = @_; $self->{rotate_logs}->print($message); }
Log::Pony pass arguments without 'log_level' to $logger->init. You can setup your logger class at this hook point.
$logger->init
The method to output log message to any device. You can output, e-mailing, send to syslog, or string to DB at this point.
Default implementation is here:
sub process { my ($self, $level, $message) = @_; my $time = $self->time(); my $trace = $self->trace_info(); print STDERR "$time [$level] $message $trace\n"; }
You can call following methods to get information:
Get a current time in localtime in following format;
2004-04-01T12:00:00
Get a trace information in following format:
at my/script.pl line 15
You can add this trace information folloing log message, then you can debug more easily.
Colorize your message for readability.
$level is string indicates level name. $message is string to colorize.
$level
$message
Return value: Colorized $message.
You can customize logging level by following methods.
You need to inherit from Log::Pony to customize logging level.
MyLogger->set_levels(qw/debug info warn crit emergency/);
You can set levels by this method.
You need pass the levels as first is whatever thing, last is important.
This methods non existent method automatically. In this case, you can call $logger->emergency($msg) method after this definition.
$logger->emergency($msg)
__PACKAGE__->set_colors( 'red on_white', 'green', 'black on_yellow', 'black on_red', 'red on_black');
Set colors for each levels. You should put order of colors are same as levels.
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>
Log::Dispatch, Log::Minimal
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Log::Pony, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Pony
CPAN shell
perl -MCPAN -e shell install Log::Pony
For more information on module installation, please visit the detailed CPAN module installation guide.