Spring Boot系列之-logging

配置文件以application.yml为例说明:

Spring Boot默认的日志组件为Logback。

一. 日志配置参数:

logging:
    file:   # 日志文件,绝对路径或相对路径
    path:   # 保存日志文件目录路径
    config: # 日志配置文件,Spring Boot默认使用classpath路径下的日志配置文件,如:logback.xml
    level:  # 日志级别
        org.springframework.web: DEBUG # 配置spring web日志级别

 

二. 更改Spring Boot日志组件为Log4j(注:Spring Boot仅仅支持Log4j 2.x版本):

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

 

三. 关于Spring Boot日志文件路径的疑惑?
同时配置了logging.path和logging.file属性,如下配置:

logging:
path: /var/log file: test.log

仅仅只会在项目根路径下产生test.log文件,不会在指定路径下产生日志文件(期望日志路径为:logging.path + logging.file)。

原因:Spring Boot中的logging.path和logging.file这2个属性,只需要配置其中之一即可,如果同时配置,则使用logging.file属性。

当配置了loggin.path属性时,将在该路径下生成spring.log文件,即:此时使用默认的日志文件名spring.log

当配置了loggin.file属性时,将在指定路径下生成指定名称的日志文件。默认为项目相对路径,可以为logging.file指定绝对路径。

logging: 
path: /var/logs # 在/var/logs目录下生成spring.log文件 file: /var/logs/test.log # 在/var/logs目录下生成test.log文件

详见:http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html 

 

【参考】
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
http://didispace.com/springbootlog/

 

转载于:https://www.cnblogs.com/nuccch/p/6221255.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值