Log::Minimal - Minimal but customizable logger.
use Log::Minimal; critf("%s","foo"); # 2010-10-20T00:25:17 [CRITICAL] foo at example.pl line 12 warnf("%d %s %s", 1, "foo", $uri); infof('foo'); debugf("foo"); print if $ENV{LM_DEBUG} is true # with full stack trace critff("%s","foo"); # 2010-10-20T00:25:17 [CRITICAL] foo at lib/Example.pm line 10, example.pl line 12 warnff("%d %s %s", 1, "foo", $uri); infoff('foo'); debugff("foo"); print if $ENV{LM_DEBUG} is true my $serialize = ddf({ 'key' => 'value' }); # die with formatted message croakf('foo'); croakff('%s %s', $code, $message);
Log::Minimal is Minimal but customizable log module.
critf("could't connect to example.com"); critf("Connection timeout timeout:%d, host:%s", 2, "example.com");
Display CRITICAL messages. When two or more arguments are passed to the function, the first argument is treated as a format of printf.
local $Log::Minimal::AUTODUMP = 1; critf({ foo => 'bar' }); critf("dump is %s", { foo => 'bar' });
If $Log::Minimal::AUTODUMP is true, reference or object message is serialized with Data::Dumper automatically.
Display WARN messages.
Display INFO messages.
Display DEBUG messages, if $ENV{LM_DEBUG} is true.
critff("could't connect to example.com"); critff("Connection timeout timeout:%d, host:%s", 2, "example.com");
Display CRITICAL messages with stack trace.
Display WARN messages with stack trace.
Display INFO messages with stack trace.
Display DEBUG messages with stack trace, if $ENV{LM_DEBUG} is true.
die with formatted $message
croakf("critical error"); # 2011-06-10T16:27:26 [ERROR] critical error at sample.pl line 23
die with formatted $message with stack trace
Utility method that serializes given value with Data::Dumper;
my $serialize = ddf($hashref);
To print debugf and debugff messages, $ENV{LM_DEBUG} must be true.
$ENV{LM_COLOR} is used as default value of $Log::Minimal::COLOR
Coloring log messages. Disabled by default.
To change the method of outputting the log, set $Log::Minimal::PRINT.
# with PSGI Application. output log with request uri. my $app = sub { my $env = shift; local $Log::Minimal::PRINT = sub { my ( $time, $type, $message, $trace,$raw_message) = @_; $env->{psgi.errors}->print( "$time [$env->{SCRIPT_NAME}] [$type] $message at $trace\n"); }; run_app(...); }
$message includes color sequences, If you want raw message text, use $raw_message. default is
sub { my ( $time, $type, $message, $trace,$raw_message) = @_; warn "$time [$type] $message at $trace\n"; }
To change the format of die message, set $Log::Minimal::DIE.
local $Log::Minimal::PRINT = sub { my ( $time, $type, $message, $trace) = @_; die "[$type] $message at $trace\n"; # not need time };
default is
sub { my ( $time, $type, $message, $trace) = @_; die "$time [$type] $message at $trace\n"; }
Set level to output log.
local $Log::Minimal::LOG_LEVEL = "WARN"; infof("foo"); #print nothing warnf("foo");
Support levels are DEBUG,INFO,WARN,CRITICAL and NONE. If NONE is set, no output. Default log level is DEBUG.
Serialize message with Data::Dumper.
warnf("%s",{ foo => bar}); # HASH(0x100804ed0) local $Log::Minimal::AUTODUMP = 1; warnf("dump is %s", {foo=>'bar'}); #dump is {foo=>'bar'} my $uri = URI->new("http://search.cpan.org/"); warnf("uri: '%s'", $uri); # uri: 'http://search.cpan.org/'
If message is object and has overload methods like '""' or '0+', Log::Minimal uses it instead of Data::Dumper.
Like a $Carp::CarpLevel, this variable determines how many additional call frames are to be skipped. Defaults to 0.
Masahiro Nagano <kazeburo {at} gmail.com>
Yuji Shimada (xaicron)
Yoshihiro Sugi (sugyan)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Log::Minimal, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Minimal
CPAN shell
perl -MCPAN -e shell install Log::Minimal
For more information on module installation, please visit the detailed CPAN module installation guide.