Sentry一個開源錯誤跟蹤工具,可以讓開發者實時監控和修復崩潰程序,持續迭代,提升效率。程序代碼中集成Sentry以後,可以將異常信息發送到Sentry服務,而且能夠經過配置Sentry插件,可以實現經過郵件、釘釘等告警通知。 Sentry官網:https://sentry.io/welcome/
Sentry中提供log4j的Appender,能夠將log中特定等級日誌發送到Sentry中
代碼中集成Sentry
使用Maven:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>1.7.5</version>
</dependency>java
使用SBT:
libraryDependencies += "io.sentry" % "sentry-logback" % "1.7.5"git
logback.xml的配置github
<configuration>
<!-- Configure the Console appender -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>app
<!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
</appender>ide
<!-- Enable the Console and Sentry appenders, Console is provided as an example
of a non-Sentry logger that is set to a different logging threshold -->
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="Sentry" />
</root>
</configuration>工具
有如下集中實現的方式。spa
我採用的是第二個方式,配置啓動程序的JVM參數
插件
具體工程代碼能夠參考 https://github.com/chocolateBlack/loghub-logback-sentry日誌