syslogappender
1.0.0
用于日志返回的系统日志附加程序,具有完整的 RFC-5424 支持
一个 Logback 附加程序,利用 [syslog4j][] 通过与 RFC-5424 格式兼容的 syslog 向远程系统发送日志消息。
Logback 的现有系统日志附加程序仅提供通过 UDP 发送消息的功能。使用 syslog-java-client 允许我们通过 TCP 发送消息,并且可以选择通过使用 TLS 通过 TCP 发送消息来加密它们。该库还负责根据 RFC-5424 添加消息长度,以便包含新行的日志行正常工作。
使用 https://bintray.com/serioussam/oss/com.github.serioussam%3Asyslogappender 进行设置 将其添加到您的pom.xml
中:
< dependency >
< groupId >com.github.serioussam</ groupId >
< artifactId >syslogappender</ artifactId >
< version >1.0.0</ version >
</ dependency >
然后将附加程序添加到您的logback.xml
中。
如果不使用 Maven,请下载 [logback-syslog4j-1.0.0.jar][] 和最新的 [syslog4j][] JAR。除了 Logback 本身之外,还将这些文件放置在类路径中。
< appender name = " SYSLOG-TLS " class = " com.github.serioussam.syslogappender.SyslogAppender " >
< layout class = " ch.qos.logback.classic.PatternLayout " >
< pattern >%date %-5level %logger{35} - %message%n</ pattern >
</ layout >
< syslogConfig class = " SyslogConfig " >
<!-- remote system to log to -->
< host >localhost</ host >
<!-- remote port to log to -->
< port >514</ port >
<!-- program name to log as -->
< programName >java-app</ programName >
<!-- protocol TCP_TLS -->
< protocol >TCP_TLS</ protocol >
</ syslogConfig >
</ appender >
< root level = " DEBUG " >
< appender-ref ref = " SYSLOG-TLS " />
</ root >
< appender name = " SYSLOG-TCP " class = " com.github.serioussam.syslogappender.SyslogAppender " >
< layout class = " ch.qos.logback.classic.PatternLayout " >
< pattern >%date %-5level %logger{35} - %message%n</ pattern >
</ layout >
< syslogConfig class = " SyslogConfig " >
<!-- remote system to log to -->
< host >localhost</ host >
<!-- remote port to log to -->
< port >514</ port >
<!-- program name to log as -->
< programName >java-app</ programName >
<!-- protocol TCP -->
< protocol >TCP</ protocol >
</ syslogConfig >
</ appender >
< root level = " DEBUG " >
< appender-ref ref = " SYSLOG-TCP " />
</ root >
< appender name = " SYSLOG-UDP " class = " com.github.serioussam.syslogappender.SyslogAppender " >
< layout class = " ch.qos.logback.classic.PatternLayout " >
< pattern >%date %-5level %logger{35} - %message%n</ pattern >
</ layout >
< syslogConfig class = " SyslogConfig " >
<!-- remote system to log to -->
< host >localhost</ host >
<!-- remote port to log to -->
< port >514</ port >
<!-- program name to log as -->
< programName >java-app</ programName >
<!-- protocol UDP -->
< protocol >UDP</ protocol >
</ syslogConfig >
</ appender >
< root level = " DEBUG " >
< appender-ref ref = " SYSLOG-UDP " />
</ root >