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日志