--> 使用模块Sys::Syslog
将日志发送给本机
#!/usr/bin/perl -w
use strict;
use Sys::Syslog qw(:DEFAULT setlogsock);
my $ident="inotify"; #进程命
my $logopt="ndelay";
my $facility="local2"; #设备名
my $priority="info"; #日志级别
openlog $ident, $logopt, $facility;
syslog($priority,"hello"); #记入日志
closelog;
将日志发送到日志主机
#!/usr/bin/perl -w
use strict;
use Sys::Syslog qw(:DEFAULT setlogsock);
my $ident="inotify"; #进程命
my $logopt="ndelay";
my $facility="local2"; #设备名
my $priority="info"; #日志级别
setlogsock('udp','log.supersun.biz');
syslog($priority,"hello"); #记入日志
closelog;
如果使用tcp协议传输日志:
setlogsock('tcp','log.supersun.biz');
同时,更改/etc/services
将514/tcp的服务名改为syslog
log option的几个可设定的值
* 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 the connection 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.
syslog记入的日志格式
Mar 18 13:17:13 host1.supersun.biz inotify: test message
时间 接收到日志的时间
主机名 发送日志的主机
进程名 前面定义的$ident
日志内容
相关文章
使用syslog-ng配置日志主机
将防火墙的日志发送给日志主机

发表评论