[summary] log4j on sentry practice
1. SentrySentry is an open source error tracking tool that allows developers to monitor and repair crashed programs in real time, iterate continuously and improve efficiency. After the Sentry is integrated into the program code, the exception information can be sent to the Sentry service, and the alarm notification through mail, nails and other alarm can be realized by configuring the Sentry plug-in. Sentry official website: Appender of log4j is provided in https://sentry.io/welcome/2 and log4j/logback on sentrySentry, and specific level logs in log can be sent to Sentry.
Integrate Sentry into the code
Use Maven:
Io.sentry
Sentry-logback
1.7.5
Use SBT:
LibraryDependencies + = "io.sentry"% "sentry-logback"% "1.7.5"
Configuration of logback.xml
% d {HH:mm:ss.SSS} [% thread]%-5level% logger {36} -% msg%n
WARN
3. Configure DSN (Data Source Name) of Sentry
There are the following centralized implementation methods.
Sentry.properties configured under classpath
Dsn= https://public:private@host:port/1 is configured in Java system Properties (Java System Properties)
Java-Dsentry.dsn= https://public:private@host:port/1-jar app.jar is configured in the system environment variable
SENTRY_DSN= https://public:private@host:port/1 java-jar app.jar is implemented in code
Import io.sentry.Sentry
Sentry.init ("https://public:private@host:port/1");"
I used the second way to configure the JVM parameters of the startup program
4. Code implementation
For specific project codes, please refer to https://github.com/chocolateBlack/loghub-logback-sentry.