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 是指定的文件句柄
    };
  • 相关阅读:
    人脸识别的一些网站
    41、过滤驱动程序
    13、ActiveX控件
    42、驱动程序调试
    20、宽字符串与字符串间的相互转换
    14、HOOK和数据库访问
    43、Windows驱动程序模型笔记(一)
    7、注册表读写的一个例子
    12、动态链接库,dll
    40、总结IRP,handling IRPs,Part II
  • 原文地址:https://www.cnblogs.com/tjxwg/p/2913076.html
Copyright © 2011-2022 走看看