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 >