perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志
perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=30572348&id=5603558
自定义日志模块(Sys::Syslog)
1、语法:
use Sys::Syslog; # all except setlogsock(), or:
use Sys::Syslog qw(:DEFAULT setlogsock); # default set, plus setlogsock()增强版
use Sys::Syslog qw(:standard :macros); # standard functions, plus macros
2、setlogsock使用
setlogsock($sock_type)
setlogsock($sock_type, $stream_location)
· "native" - use the native C functions from your syslog(3) library (added in "Sys::Syslog" 0.15).
· "eventlog" - send messages to the Win32 events logger (Win32 only; added in "Sys::Syslog" 0.19).
· "tcp" - connect to a TCP socket, on the "syslog/tcp" or "syslogng/tcp" service.
· "udp" - connect to a UDP socket, on the "syslog/udp" service.
· "inet" - connect to an INET socket, either TCP or UDP, tried in that order.
· "unix" - connect to a UNIX domain socket (in some systems a character special device). The name of that socket is
the second parameter or, if you omit the second parameter, the value returned by the "_PATH_LOG" macro (if your
system defines it), or /dev/log or /dev/conslog, whatever is writable.
· "stream" - connect to the stream indicated by the pathname provided as the optional second parameter, or, if
omitted, to /dev/conslog. For example Solaris and IRIX system may prefer "stream" instead of "unix".
· "pipe" - connect to the named pipe indicated by the pathname provided as the optional second parameter, or, if
omitted, to the value returned by the "_PATH_LOG" macro (if your system defines it), or /dev/log (added in
"Sys::Syslog" 0.21).
· "console" - send messages directly to the console, as for the "cons" option of "openlog()".
3、函数:
3.1openlog函数
openlog($ident, $logopt, $facility;) 定义日志内容
$ident //每一个日志信息前均会附加$ident
$logopt //选项
$facility // 类型
logopt选项:
· "cons" - This option is ignored, since the failover mechanism will drop down to the console automatically if all other media fail.
· "ndelay" - Open the connection immediately (normally, the connection is opened when the first message is logged).
· "nofatal" - When set to true, "openlog()" and "syslog()" will only emit warnings instead of dying if theconnection to the syslog can't be established.
· "nowait" - Don't wait for child processes that may have been created while logging the message. (The GNU C library does not create a child process, so this option has no effect on Linux.)
· "perror" - Write the message to standard error output as well to the system log.
· "pid" - Include PID with each message.
facility类型:
auth 用户认证
authpriv 有特权的用户认证
cron cron守护进程
daemon 各种系统守护进程
ftp ftp守护进程
kern 内核消息
local0-local7 保留用于本地用法
lpr 打印机
mail 邮件
news 新闻
syslog 内部syslog
uucp uucp系统
user 各种用户程序来的消息
3.2syslog函数
syslog($priority, $message)
syslog($priority, $format, @args)
syslog可定义优先级
$priority can specify a level, or a level and a facility.
*先用openlog()定义格式,syslog()定义内容 //use "openlog()" before using "syslog()"
3.3closelog()
Closes the log file and returns true on success.
具体例子:
setlogsock(["unix", "udp", "native", "tcp"]); #通过unix,udp,tcp socket连接LOG
my $identity = "czw-syslog";
my @options = ('cons','pid');
my $facility = "local5";
openlog($identity,\@options,$facility); #定义了格式等
syslog('info', "message");
-----------------------------
syslog('err',$message);
===================================
perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志的更多相关文章
- sys,os,模块-正则表达式
# *__conding:utf-8__* """"我是注释""" sys,os模块 import sysimport os pr ...
- day2_python的数据类型,sys,os模块,编码解码,列表,字典
今天主要了解了python的数据类型,sys,os模块,编码解码,列表,字典 1.数据类型:int(python3没有长整型)文本总是Unicode,str表示二进制用byte类表示布尔型:True( ...
- Perl 学习笔记-模块
1.Perl模块介绍 2个来源, 一个是随Perl发行版本一同打包, 只要安装了Perl就可以使用; 另一种是需要从CPAN上下载,自己安装. 寻找模块之前, 先检查系统上是否已经安装过了, ...
- man syslog | col -b > syslog.txt
linux man手册导出,解决man乱码 man syslog | col -b > syslog.txt
- time | sys | os 模块,递归删除文件,项目分析
一,复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块 ...
- python模块知识二 random -- 随机模块、序列化 、os模块、sys -- 系统模块
4.random -- 随机模块 a-z:97 ~ 122 A-Z :65 ~ 90 import random #浮点数 print(random.random())#0~1,不可指定 print( ...
- os 和 sys 的模块使用方法和模块
os 的模块 方法 os.remove()删除文件 os.rename()重命名文件 os.walk()生成目录树下的所有文件名 os.chdir()改变目录 os.mkdir/maked ...
- python第二十课——math模块中常用的函数
属性: e:自然数 pi:圆周率 函数: ceil():向上取整 floor():向下取整 sqrt():开平方根 radians():角度转弧度 degrees():弧度转角度 import mat ...
- Python:包、模块、类、函数的调用
一.关系 包一般指文件夹或者安装包(安装包一般也是压缩后的文件夹),里面包含多个.py文件(必须有一个__init__.py文件),一般也含有多个子包(或子文件夹): 一般一个.py文件就是一个模块, ...
随机推荐
- DevOps - 版本控制 - Git
配置 .gitignore 配置 .gitignore 配置文件用于配置不需要加入版本管理的文件,配置好该文件可以为我们的版本管理带来很大的便利. 有些时候,你必须把某些文件放到Git工作目录中,但又 ...
- 阿里云SSL证书到期(续期)图文教程
今天公司项目突然报错 后来查询是SSL证书过期了.友情提示: 证书产品仅支持新签发.不支持续费.证书到期前需在阿里云SSL证书控制台重新购买和申请证书. 登录阿里云控制台,点击产品与服务,在搜索框搜索 ...
- 【ospf-vlink虚拟连接】
根据项目需求,搭建好如下拓扑图 配置rt1的环回 口地址及g0/0/0的ip地址 配置rt1的ospf 配置rt2的环回口地址和g0/0/1及g0/0/0的ip地址 \ 配置rt2的ospf 同理,配 ...
- Object.keys方法
我们有时需要知道对象的所有属性,原生js给我们提供了一个很好的方法:Object.keys(),该方法返回一个数组 传入对象,返回属性名 var obj = {'a':'123','b':'345'} ...
- php中处理中文的注意
使用session的情况下------------------------- php.ini register_globals = Off 保持关闭,开启可能会导致iconv转换中文产生错误 修改ph ...
- NOIP模拟 candy
题目描述 一天,小 DD 决定买一些糖果.他决定在两家不同的商店中买糖果,来体验更多的口味. 在每家商店中都有 nn 颗糖果,每颗糖果都有一个权值:愉悦度,代表小 DD 觉得这种糖果有多好吃.其中,第 ...
- 网站mysql防止sql注入攻击 3种方法总结
mysql数据库一直以来都遭受到sql注入攻击的影响,很多网站,包括目前的PC端以及手机端都在使用php+mysql数据库这种架构,大多数网站受到的攻击都是与sql注入攻击有关,那么mysql数据库如 ...
- uva 12096 - The SetStack Computer(集合栈)
例题5-5 集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096) 有一个专门为了集合运算而设计的"集合栈"计算机. ...
- Python3 模块、包调用&路径
''' 以下代码均为讲解,不能实际操作 ''' ''' 博客园 Infi_chu ''' ''' 模块的优点: 1.高可维护性 2.可以大大减少编写的代码量 模块一共有三种: 1.Python标准库 ...
- PHP.42-TP框架商城应用实例-后台17-商品属性3-商品分类的修改与删除
商品分类的修改 1.改表单Goods/edit.html,加下拉框 2.因为商品属性修改涉及商品属性表goods_attr{id,attr_value,attr_id,goods_id}与属性表att ...