logback-warning

Project source: github.com/sixj0/logba…

Function introduction:

The Appender module can be used with Logback logs to generate alarms when error logs are generated. Currently, alarms are generated in the tack notification mode. By default, all error logs will generate alarms. Determine whether alarms are required based on error logs.

Usage:

  1. Introduction of depend on

    <dependency>
      <groupId>com.sixj</groupId>
      <artifactId>logback-warning-platform</artifactId>
      <version>1.0.0 - the SNAPSHOT</version>
    </dependency>
    Copy the code
  2. Add the configuration

    # Configure the webHook generated by the pin swarm robot
    dingDing.logback.webHook=https://oapi.dingtalk.com/robot/send?access_token
    # When an alarm is generated, the mobile phone number of the @ user is required. Multiple mobile phone numbers are separated by commas (,)
    dingDing.logback.phones=15501176233
    Copy the code
  3. Add an Appender to the logback-spring. XML file

    <! -- Abnormal log monitoring nail alarm -->
    <appender name="SendErrorMsgAppender"
              class="com.sixj.appender.SendErrorMsgAppender">
    </appender>
    
    <logger name="root" level="info" additivity="false">
      <appender-ref ref="SendErrorMsgAppender"/>
    </logger>
    Copy the code
  4. By default, all error logs generate alarms. If certain error log content is required to generate alarms, you need to implement the Verdict method of the LogWaringRule interface and define a matching rule. An alarm is generated only when the log information matches the rule, for example:

    @Component
    public class MyLogWaringRule implements LogWaringRule {
    
        @Override
        public boolean verdict(String errorMessage) {
            // An alarm is generated when error log information contains' URL '
            return errorMessage.contains("url"); }}Copy the code