springBoot输出日志到指定目录

以输出日志文件到D:/data/log为例

版本一

一、在application.properties加上如下配置

logging.path=D:/data/log
logging.config=classpath:logback-spring.xml
logging.level.root = debug

如果要输出mybatis的sql,就加一行配置指定该目录输出为debug

logging.level.mapper所在目录= debug

二、在resources下新建 logback-spring.xml 文件








    

    logback
    
    

    
    
    
    
    
    
    


    
    
        
        
            info
        
        
            ${CONSOLE_LOG_PATTERN}
            
            UTF-8
        
    


    

    
    
        
        ${log.path}/log_debug.log
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
            UTF-8 
        
        
        
            
            ${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log
            
                100MB
            
            
            15
        
        
        
            debug
            ACCEPT
            DENY
        
    

    
    
        
        ${log.path}/log_info.log
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
            UTF-8
        
        
        
            
            ${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log
            
                100MB
            
            
            15
        
        
        
            info
            ACCEPT
            DENY
        
    

    
    
        
        ${log.path}/log_warn.log
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
            UTF-8 
        
        
        
            ${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log
            
                100MB
            
            
            15
        
        
        
            warn
            ACCEPT
            DENY
        
    


    
    
        
        ${log.path}/log_error.log
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
            UTF-8 
        
        
        
            ${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log
            
                100MB
            
            
            15
        
        
        
            ERROR
            ACCEPT
            DENY
        
    

    
    
    
    


    

    
    
        
    

    
        
        
        
        
        
    

    
    
    
    
    
    
    
    
    
    

 

简洁版:

#日志路径
logging.path=/data/logs/evaluate-destine
#日志配置文件
logging.config=classpath:logback-spring.xml
logging.level.包名=debug
logging.level.org.springframework=WARN
logging.level.org.spring.springboot.dao=DEBUG
#mvc返回时间数据为时间戳
spring.jackson.serialization.write-dates-as-timestamps = true

 logback-spring.xml 文件



    

    
        ${LOG_PATH}/info.log
        
            ${LOG_PATH}/info-%d{yyyyMMdd}.log.%i
            
                500MB
            
            100
        
        
            
            %d{yyyy-MM-dd HH:mm:ss.SSS} -%5p ${PID:-} [%15.15t] %-40.40logger{39} : %m%n
        
    

    
        
            ERROR
        
        ${LOG_PATH}/error.log
        
            ${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
            
            
                500MB
            
            100
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} -%5p ${PID:-} [%15.15t] %-40.40logger{39} : %m%n
        
    

    
        
        
    

 

 

 

你可能感兴趣的:(java)