Log::Minimal 小型可定制的log模块
语法:
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);
序列化复杂数据结构输出日志
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/'
修改日志的输出级别,默认为INFO级别
$ENV{LM_DEBUG}=1; 修改环境变量
local
$Log
::Minimal::LOG_LEVEL =
"INFO"
; #代码控制
定制log文件
#定制输出的格式 local $Log::Minimal::PRINT = sub { my ( $time, $type, $message, $trace) = @_; print("$time $type $message $trace\n"); };
指定文件进行log日志的输出
local $Log::Minimal::PRINT = sub { my ( $time, $type, $message, $trace) = @_; print {$fh} "$time [$type] $message at $trace\n"; # $fh 是指定的文件句柄 };