前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Boot系列之-logging

Spring Boot系列之-logging

作者头像
编程随笔
发布2019-09-11 15:27:31
7790
发布2019-09-11 15:27:31
举报
文章被收录于专栏:后端开发随笔后端开发随笔

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

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

一. 日志配置参数:

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

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

代码语言:javascript
复制
<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属性,如下配置:

代码语言:javascript
复制
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指定绝对路径。

代码语言:javascript
复制
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/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-12-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档