zoukankan      html  css  js  c++  java
  • 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 是指定的文件句柄
    };
  • 相关阅读:
    hdu 4027 Can you answer these queries?
    hdu 4041 Eliminate Witches!
    hdu 4036 Rolling Hongshu
    pku 2828 Buy Tickets
    hdu 4016 Magic Bitwise And Operation
    pku2886 Who Gets the Most Candies?(线段树+反素数打表)
    hdu 4039 The Social Network
    hdu 4023 Game
    苹果官方指南:Cocoa框架(2)(非原创)
    cocos2d 中 CCNode and CCAction
  • 原文地址:https://www.cnblogs.com/tjxwg/p/2913076.html
Copyright © 2011-2022 走看看