1. log4j配置内容如下
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.SyslogHost=127.0.0.1
log4j.appender.syslog.Port=514
log4j.appender.syslog.Facility=LOCAL1
log4j.appender.syslog.header=true
log4j.appender.syslog.Threshold=INFO
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern=%5p | %c{1}-%M [%d{yyyy-MM-dd HH:mm:ss}] - %m%n
log4j.rootLogger=info,stdout,syslog
2. logback配置内容如下:
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>127.0.0.1</syslogHost>
<facility>LOCAL1</facility>
<suffixPattern>[%thread] %logger %msg</suffixPattern>
</appender>
3. syslog配置过程(以下是ubuntu设置的过程,其他环境不一定完全适用,但也是雷同)
ubuntu服务器默认安装有rsyslog服务,如果没有安装可以运行命令安装 apt-get install rsyslog
修改配置文件 vi etc/rsyslog.conf
将#删除,使UDP端口接收生效
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
修改完配置后重启服务 service rsyslog restart