springboot日志

slf4j+logback

1、application.properties文件增加内容

# 日志目录的绝对路径
logging.file.path=/www/wwwlog/
logging.config=classpath:logback-spring.xml

2、logback-spring.xml文件增加内容(classpath默认为src/main/resources文件夹)



    
    

    
    
        
        
            
            %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID:- } [%t] :: {%logger Line:%-3L} -->> %msg%n
        
    

    
    
        
            
            ${LOG_PATH}/error/log-%d{yyyy-MM-dd}.log
            
            7
        
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID:- } [%t] :: {%logger Line:%-3L} -->> %msg%n
        
        
            ERROR
        
    

    
    
        
            
            ${LOG_PATH}/info/log-%d{yyyy-MM-dd}.log
            
            7
        
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID:- } [%t] :: {%logger Line:%-3L} -->> %msg%n
        
        
            INFO
        
    

    
    
        
        
    


3、使用

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

public class HelloWorld {
    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(HelloWorld.class);
        logger.info("Hello World");
    }
}

你可能感兴趣的:(springboot日志)