Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[summary] log4j on sentry practice

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 302

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report