NAME
Log::Minimal - Minimal but customizable logger.
SYNOPSIS
use Log::Minimal;
critf("%s","foo"); # 2010-10-20T00:25:17 [CRITICAL] foo at example.pl line 12
warnf("%d %s", 1, "foo");
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", 1, "foo");
infoff("foo");
debugff("foo"); print if $ENV{LM_DEBUG} is true
my $serialize = ddf({ 'key' => 'value' });
DESCRIPTION
Log::Minimal is Minimal but customizable log module.
EXPORT FUNCTIONS
- critf(($message:Str|$format:Str,@list:Array));
-
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.
- warnf(($message:Str|$format:Str,@list:Array));
-
Display WARN messages.
- infof(($message:Str|$format:Str,@list:Array));
-
Display INFO messages.
- debugf(($message:Str|$format:Str,@list:Array));
-
Display DEBUG messages, if $ENV{LM_DEBUG} is true.
- critff(($message:Str|$format:Str,@list:Array));
-
critff("could't connect to example.com"); critff("Connection timeout timeout:%d, host:%s", 2, "example.com");
Display CRITICAL messages with stack trace.
- warnff(($message:Str|$format:Str,@list:Array));
-
Display WARN messages with stack trace.
- infoff(($message:Str|$format:Str,@list:Array));
-
Display INFO messages with stack trace.
- debugff(($message:Str|$format:Str,@list:Array));
-
Display DEBUG messages with stack trace, if $ENV{LM_DEBUG} is true.
- ddf($value:Any)
-
Utility method that serializes given value with Data::Dumper;
warnf( "dump is %s, another dump is %s", ddf($hashref), ddf($arrayref) );
ENVIRONMENT
To print debugf and debugff messages, $ENV{LM_DEBUG} must be true.
CUSTOMIZE
- $Log::Minimal::PRINT
-
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) = @_; $env->{psgi.errors}->print( "$time [$env->{SCRIPT_NAME}] [$type] $message at $trace\n"); }; run_app(...); }
default is
sub { my ( $time, $type, $message, $trace) = @_; warn "$time [$type] $message at $trace\n"; }
- $Log::Minimal::LOG_LEVEL
-
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.
AUTHOR
Masahiro Nagano <kazeburo {at} gmail.com>
THANKS TO
Yuji Shimada (xaicron)
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.