Use logback custom appender not take effect

Project colleagues used logback output logging, uses a simple implementation class as a custom output class, and using code configuration is as follows:

 

1 import ch.qos.logback.classic.spi.LoggingEvent;
2 import ch.qos.logback.core.AppenderBase;
3 
4 public class MyAppender extends AppenderBase<LoggingEvent> {
5     @Override
6     protected void append(LoggingEvent eventObject) {
7         System.out.println("Test append method");
8     }
9 }
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" scanPeriod="60 seconds" debug="false">
    <appender name="myAppender" class="com.hx.MyAppender"/>
    <logger name="qcLogger" additivity="false">
        <level value="info"/>
        <appender-ref ref="myAppender"/>
    </logger>
</configuration>
<dependency>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-api</artifactId>
     <version>1.7.26</version>
</dependency>
<dependency>
     <groupId>ch.qos.logback</groupId>
     <artifactId>logback-classic</artifactId>
     <version>1.2.3 </version>
</dependency>

 

I use to import IDEA project, still can not call the append method, initially suspected to be the source code or configuration file issue, no difference in contrast colleagues code;

Then I exclude my local environmental interference, the code running in the new project, still can not call, I try to adjust the dependent version, the version sl4j-api tone for 1.6.x, the result of the call is successful, but it is warning

 

 

 After I recovered sl4j-api to 1.7.x you can also call succeeds, and the warning disappears, so far considered to solve the problem of output, although the final did not know the cause of this problem,

But as a pragmatic developer, the face of such problems, you can try to change some of the inherent approach might be a way to solve the problem.

Guess you like

Origin www.cnblogs.com/fengmy/p/11485475.html