环境信息

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. 一起来学linux:磁盘与文件系统:

    对于文件系统来说,windows上最长用的就是FAT32和NTFS.在Linux上时候用的是Ext2.在linux中,文件权限与文件属性这两部分会被存储在不同的块,权限与权限放置到inode中,实际数 ...

  2. Oracle序列更新

    Oracle 数据库的时候,有时候会选择使用自增序列作为主键.但是在开发过程中往往会遇到一些不规范的操作,导致表的主键值不是使用序列插入的.这样在数据移植的时候就会出现各种各样的问题.当然数据库主键不 ...

  3. 基于springboot的Dubbo的常规总结

    1.引入jar包: <!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>com.alibaba.spring.b ...

  4. 用margin还是用padding?(3)—— 负margin实战

    看过一篇文章是关于我知道你不知道的负Margin,里面对margin做了总结: 当margin四个值都为正数值的话,那么margin按照正常逻辑同周围元素产生边距.当元素margin的top和left ...

  5. Log4j输出格式控制--log4j的PatternLayout参数含义

      参数 说明 例子 %c 列出logger名字空间的全称,如果加上{<层数>}表示列出从最内层算起的指定层数的名字空间 log4j配置文件参数举例 输出显示媒介 假设当前logger名字 ...

  6. js实现打字机效果

    var s = 'Hello World! Hello World! Hello World!'; var con = $('.container'); var index = 0; var leng ...

  7. hdu-3018 Ant Trip(欧拉路径)

    题目链接: Ant Trip Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

  8. codeforces 665A A. Buses Between Cities(水题)

    题目链接: A. Buses Between Cities time limit per test 1 second memory limit per test 256 megabytes input ...

  9. SVN与CVS比较-怎度网

    SVN与CVS比较 所有的文档都显示SVN可以取代CVS,同时SVN的问题和缺点都被隐藏了.不幸的是,我们并不认为SVN是CVS的替代品,尽管很多缺陷都被修改了.更有甚者,它甚至让人重回VSS.CVS ...

  10. 小工具之Synergy

    用于两个主机共享键盘和鼠标的工具: 软件名字:synergy软件主页: http://synergy-foss.org支持平台:linux,mac,windows 通吃 作用:通过网络在多台主机之间共 ...