zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    SIGGRAPH
    用JSP实现的商城购物车模块
    大数运算
    编写高质量代码改善java程序的151个建议——导航开篇
    Spring3.0 AOP 具体解释
    HDU3400+三分
    Java实现BFS广度优先查找
    Java实现BFS广度优先查找
    Java实现BFS广度优先查找
    Java实现BFS广度优先查找
  • 原文地址:https://www.cnblogs.com/nuccch/p/6221255.html
Copyright © 2011-2022 走看看