环境信息

ubuntu 12.04 64位 桌面版

Log-Log4perl 的介绍网址:http://search.cpan.org/~mschilli/Log-Log4perl-1.49/lib/Log/Log4perl.pm

下载链接

wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHILLI/Log-Log4perl-1.49.tar.gz

安装

perl Makefile.PL
make && make install

测试LOG4perl 模块的配置文件 log.conf

log4perl.category.Foo.Bar=DEBUG,Logfile,Screen
log4perl.rootLogger=DEBUG,Logfile,Screen log4perl.appender.Logfile=Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename=\
sub { return &log4::set_log_name(); }
log4perl.appender.Logfile.layout=Log::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern =%d{yyyy/M/d HH:mm:ss} %F %L - %m%n log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr =
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern =%d{yyyy/M/d HH:mm:ss} %F %L - %m%n

测试test.pl 程序

#!/usr/bin/perl
package log4;
use strict;
use FindBin qw($Bin);
use lib "$Bin/lib";
print "$Bin\n";
use Log::Log4perl qw(get_logger);
my $log = get_logger(__PACKAGE__);
my $log_name="log4.log";
my $log_conf = "log.conf";
print "$log_conf\n"; # Check config every 60 secs
Log::Log4perl::init_and_watch($log_conf,); $log->debug("Debug message");
$log->info("Info message");
$log->error("Error message");
$log->info(&ping);
sub ping
{ my @ping=readpipe("ping -c 4 127.0.0.1");
return @ping;
}
sub set_log_name
{
return $log_name;
}

执行测试程序命令

perl test.pl

打印结果

log.conf
// :: test.pl - Debug message
// :: test.pl - Info message
// :: test.pl - Error message
// :: test.pl - PING 127.0.0.1 (127.0.0.1) () bytes of data.
bytes from 127.0.0.1: icmp_req= ttl= time=0.032 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.027 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.026 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.027 ms --- 127.0.0.1 ping statistics ---
packets transmitted, received, % packet loss, time 2999ms
rtt min/avg/max/mdev = 0.026/0.028/0.032/0.002 ms

并且日志文件 log4.log 内容如下

// :: test.pl  - Debug message
// :: test.pl - Info message
// :: test.pl - Error message
// :: test.pl - PING 127.0.0.1 (127.0.0.1) () bytes of data.
bytes from 127.0.0.1: icmp_req= ttl= time=0.023 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.028 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.028 ms
bytes from 127.0.0.1: icmp_req= ttl= time=0.027 ms --- 127.0.0.1 ping statistics ---
packets transmitted, received, % packet loss, time 2999ms
rtt min/avg/max/mdev = 0.023/0.026/0.028/0.005 ms

perl 安装LOG4perl 模块的更多相关文章

  1. perl 安装 ZooKeeper模块

    1072 ./configure --libdir=/usr/lib 1073 make 1074 make install 1075 cpan ZooKeeper [root@wx03 c]# pe ...

  2. Linux下安装Perl和Perl的DBI模块

    今天在虚拟机测试shell脚本的时候,有些命令使用不了. 比如说 mysqlhotcopy ,它提示Perl的版本太低. 我用的 RedHat9 的Perl才5.8.0版本...(2002年以前的) ...

  3. 【Perl】如何安装Bioperl模块?

    目录 失败尝试一:使用cpanm 失败尝试二:使用CPAN 成功尝试:直接conda安装bioperl 没有尝试:源码安装bioperl 生信软件绕不过Perl,Perl绕不过Bioperl.而Bio ...

  4. 配置perl-cgi的运行环境,由于Active Perl安装在d:\perl

    Apache 1.3.22 for Win32+PHP 4.0.6+Active Perl 5.006001+Zend Optimizer v1.1.0+mod_gzip 1.3.19.1a+MySQ ...

  5. Python学习笔记十_模块、第三方模块安装、模块导入

    一.模块.包 1.模块 模块实质上就是一个python文件.它是用来组织代码的,意思就是把python代码写到里面,文件名就是模块的名称,test.py test就是模块的名称 2.包 包,packa ...

  6. perl中一些模块的ubuntu中依赖包

    GD 先更新系统中的依赖包: sudo apt-get update sudo apt-get upgrade 进入 cpan> install GD 会提示没有安装libgd模块. 所以,先需 ...

  7. Python学习之==>第三方模块的安装、模块导入

    一.模块&包 1.模块 模块实质上就是一个Python文件,它是用来组织代码的.意思就是把Python代码写在里面,文件名就是模块的名称.例如:random.py,random就是模块的名称. ...

  8. 查看npm全局安装的模块

    1.查看所有高级的npm moudles npm list --depth= 2.查看所有全局安装的模块 npm list --depth= -global

  9. 使用pip安装BeautifulSoup4模块

    1.测试是否安装了BeautifulSoup4模块 import bs4 print bs4 执行报错说明没有安装该模块 Traceback (most recent call last): File ...

随机推荐

  1. Axure实现Tab选项卡切换功能

    这几天用Axure画原型图的过程中,须要实现Tab选项卡切换的效果,但Axure中并没有类似于Tab控件的部件,所以能够用Axure中的动态面板(Dynamic Panel)来实现. 本文以已经汉化的 ...

  2. linux环境下远程访问ftp

    sftp ftpuser@127.0.0.1 使用sftp命令 ftpuser是用户名 127.0.0.1是目标ip 亲测好使.

  3. 负载均衡LVS

    可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...

  4. pypi指定下载源

    pip install -i http://pypi.douban.com/simple/ scipy==0.19.0

  5. ios非UTF-8格式的网页解析

    网上有很多关于ios xml解析的方法,关于非UTF-8格式的网页解析也不少,我也试着看了好几个,但都没成功.今天无意中却弄好了,所以想和大家分享下.其实很简单,下面说下怎么得到非UTF-8格式的网页 ...

  6. codeforces B. Multitasking 解题报告

    题目链接:http://codeforces.com/problemset/problem/384/B 题目意思:给出n个数组,每个数组包括m个数字,当k = 0 时,需要把n个数组都按照从小到大的顺 ...

  7. Java丨时间判断谁前谁后

    直奔主题: String date_str1 = "2016-06-02 23:03:123"; String date_str2 = "2016-06-03 03:03 ...

  8. codeforces 669A A. Little Artem and Presents(水题)

    题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...

  9. 【C】论‘\r’和'\n'的纯粹性

  10. 「网络流24题」「LuoguP3358」 最长k可重区间集问题(费用流

    题目描述 对于给定的开区间集合 I 和正整数 k,计算开区间集合 I 的最长 k可重区间集的长度. 输入输出格式 输入格式: 的第 1 行有 2 个正整数 n和 k,分别表示开区间的个数和开区间的可重 ...