springboot多环境配置logback

springboot多环境配置logback

    • 1. 创建springboot项目
    • 2. 引入相关依赖
    • 3. 在springboot的yml文件中对logging进行配置
    • 4. logback-spring.xml

1. 创建springboot项目

直接使用idea创建或者官网下载包导入这里就不做过多赘述。

2. 引入相关依赖

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile 'mysql:mysql-connector-java:6.0.6'
    compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
    compile 'org.mybatis.generator:mybatis-generator-core:1.3.2'
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Spring Boot 集成logback需要添加spring-boot-starter-logging依赖,而此依赖已经在spring-boot-starter中添加过了,所以不用再添加此依赖了(如下图)
springboot多环境配置logback_第1张图片

3. 在springboot的yml文件中对logging进行配置

application-dev.yml:

logging:
  path: D:\\log\\dev
  config: classpath:logback-spring.xml
  level:
    root: debug

application-test.yml:

logging:
  path: D:\\log\\test
  config: classpath:logback-spring.xml
  level:
    root: info

4. logback-spring.xml



    
    
     
    
    

    
    
    
    

    
    
        
            ${CONSOLE_LOG_PATTERN}
        
    

    
    
        
            ${LOG_PATH}/${LOG_NAME}.%d{yyyy-MM-dd}.%i.log
            512MB
            30
        
        
            %d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
        
    

    
    
        0
        500
        
    

    
    
        
            
            
        
    

    
    
        
            
            
        
    

    
    
        
        
        
            
            
        
    

参考:
蝈蝈的博客 - Spring Boot教程(五):默认日志logback
朱兆麟 - Spring Boot Logging 配置

结合了上面两个博客的配置 加上springProperty 标签的应用

希望可以帮到各位!

你可能感兴趣的:(springboot)