日志处理方案(Slf4j+logback)

依赖



    org.slf4j
    slf4j-api
    1.7.26


    ch.qos.logback
    logback-classic
    1.2.3


    ch.qos.logback
    logback-core
    1.2.3

logback配置





    
    
    

    
    
        ${baseDir}/${demoClassDir}.log
        
            UTF-8
            %d{yyyy-MM-dd HH:mm:ss z} [%thread] %-5level %logger{5} %M:%L - %msg%n
        
        
            ${baseDir}/${demoClassDir}/%d{yyyy-MM-dd}.log
            

            

        
    

    
    
        
            UTF-8
            %d{yyyy-MM-dd HH:mm:ss z} [%thread] %-5level %logger{5} %M:%L - %msg%n
        
    

    
        
    

    
        
    

使用

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Demo {
    private static final Logger log = LoggerFactory.getLogger(Demo.class);
    public static void main(String[] args) {
        log.info("info");
        log.warn("warn");
        log.error("error");
        log.debug("debug");
    }

}

你可能感兴趣的:(日志处理方案(Slf4j+logback))