我尝试使用log4j SyslogAppender和rsyslog
在中央日志服务器上写日志我的rsyslog版本是" 4.6.2"
首先,我根据设施名称创建了模板,它可以工作。 (你可以在conf文件中看到下面的例子" local6和" local2")
但是local0-local7和用户设施名称不够,我有很多日志文件(~30),所以我试图根据内容过滤消息,然后写入特定的日志"目录/文件"结构,但它失败
我使用了以下配置:
:msg,contains,"APP1" /var/log/%FROMHOST%/yyy/AplicationName.log
我在log4j SyslogAppender中的配置:
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.layout.conversionPattern=APP1 %d{yyyy-MM-dd HH:mm:ss} [%p] [%c] %m %n
log4j.appender.SYSLOG.Facility=USER
远程服务器上的配置
#rsyslog v3 config file
$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)
$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)
# Provides TCP syslog reception
$ModLoad imudp.so
$UDPServerRun 514
#### GLOBAL DIRECTIVES ####
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template lvl6,"/var/log/%FROMHOST%/zzz/AAA.log"
$template lvl2,"/var/log/%FROMHOST%/zzz/BBB.log"
:msg,contains,"APP1" /var/log/%FROMHOST%/yyy/APP1.log
#### RULES ####
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg *
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log
local6.* ?lvl6
local2.* ?lvl2
中央日志服务器上收到的消息如下:
Aug 8 10:50:50 APP1 2013-08-08 10:50:50 [ERROR] [AnotherLogStuff] AnotherLogStuff: Test ERROR Message