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文件就是一个模块, ...
随机推荐
- 如何用Python做自动化特征工程
机器学习的模型训练越来越自动化,但特征工程还是一个漫长的手动过程,依赖于专业的领域知识,直觉和数据处理.而特征选取恰恰是机器学习重要的先期步骤,虽然不如模型训练那样能产生直接可用的结果.本文作者将使用 ...
- python3 练习题100例 (二十七)列表元素改写
题目内容: 输入一个列表alist,要求列表中的每个元素都为正整数且不超过10: 将列表中的奇数变为它的平方,偶数除以2后打印新的列表(新的列表中所有元素仍都为整数). 可以使用以下实现列表alist ...
- 04 mysql 基础三 (进阶)
mysql 基础三 阶段一 mysql 单表查询 1.查询所有记录 select * from department; select * from student; select * from ...
- Python3 模块、包调用&路径
''' 以下代码均为讲解,不能实际操作 ''' ''' 博客园 Infi_chu ''' ''' 模块的优点: 1.高可维护性 2.可以大大减少编写的代码量 模块一共有三种: 1.Python标准库 ...
- 接口和lambda表达式笔记
接口 接口是双方,即服务提供方和想让它们的对象对服务是可用的那些类,之间约定的一种机制. 声明一个接口 public interface IntSequence{ //不提供实现,则该方法为抽象方法, ...
- SKIP(插入空行)
WRITE 'This is the 1st line'. SKIP. WRITE 'This is the 2nd line'. 跳转至某一行 SKIP TO LINE line_number. 插 ...
- Mootools 学习随笔
简单的介绍下Mootools: MooTools是一个简洁,模块化,面向对象的开源JavaScript web应用框架.在处理js.css.html时候,为web开发者提供了一个跨浏览器的js解决方案 ...
- C++学习014函数值传递和地址传递
当我们给一个函数传参数的时候,可以直接值传入函数,也给可以把一个地址传入函数 区别就是一个本身不被改变,而另一本身也在改变, 在开发时候都会用到, 这里做下记录 #include <iostre ...
- Kubernetes实战 高可用集群搭建,配置,运维与应用
1-1 K8S导学 1-2 搭建K8S集群步骤和要点介绍 1-3 搭建三节点Ubuntu环境 1-4 安装容器引擎 1-5 下载Kubeadm.node组件和命令行工具 1-6 向集群中加入worke ...
- Tuxedo 通讯方式解析
本节根据tuxedo自带samples的例子,让其运行起来.并通过这个例子,深入的理解tuxedo的通讯方式. 进入tuxedo的安装目录,samples目录下自带了一些例子 [root@localh ...