log4j22.properties syslog并不是wringing
我的Java应用程序问题是log4j2 syslog不是在“ local1.log”中写的,而是 “消息”。 my/etc/rsyslog.conf在/etc/rsyslog.conf中配置了'local1。*/var/log/local1.log'。
但是,当我从log4j22.properties中删除'appender.syslog.layout.type'''appender.syslog.layout.type'和'appender.syslog.pattern'时,syslog开始写在/var/log/local1.log上时。
我的配置不正确吗?
Syslog中是否不应用布局属性?
[/etc/rsyslog.conf]
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local1.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
...
local1.* /var/log/local1.log
[使用的log4j2库]
log4j-api-2.17.2.jar
log4j-core-2.17.2.jar
[log4j2.properties]
status = warn
name = Test
# Console appender configuration
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss} %5p (%c{1} - %M:%L) - %m%n
appender.syslog.type = Syslog
appender.syslog.name = sysLogger
appender.syslog.host = localhost
appender.syslog.port = 514
appender.syslog.protocol = UDP
appender.syslog.facility = LOCAL1
appender.syslog.layout.type = PatternLayout
appender.syslog.layout.pattern = %c{1} (%M:%L) %m\n
# Root logger level
rootLogger.level = debug
rootLogger.appenderRefs = consoleLogger, sysLogger
rootLogger.appenderRef.stdout.ref = consoleLogger
rootLogger.appenderRef.syslog.ref = sysLogger
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Log4J2的Syslog布局用于格式化 syslog消息,因此必须是
sysloglayout
(传统的BSD syslog格式)或rfc5424layOut
(现代系统锁定布局)。使用任何其他布局将导致无效的消息,RSYSLOG必须猜测消息的元数据。最值得注意的是,该设施将设置为用户
。如果要将其他数据发送到Syslog,则除了
%M
之外,还应使用RFC5424格式,并将其他信息发送为结构化数据。例如,您可以使用(以XML格式):将属性格式转换为:
几乎所有现代系统syslog服务器都可以解释结构化数据。对于rsyslog,您需要:
Log4j2's syslog layout is used to format the entire syslog message and must therefore be one of
SyslogLayout
(traditional BSD syslog format) orRfc5424Layout
(modern syslog layout). Using any other layout will result in invalid messages and RSyslog will have to guess the message's metadata. Most notably the facility will be set toUSER
.If you want to send additional data to syslog, beyond
%m
, you should use the RFC5424 format and send the additional information as structured data. For example you can use (in XML format):which translates to the properties format as:
Virtually all modern syslog servers can interpret structured data. For RSyslog you need to: