zoukankan      html  css  js  c++  java
  • 【spring boot 学习笔记】日志相关

    1. 如何启用日志?

    maven依赖中添加:spring-boot-starter-logging

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    

    实际开发中我们不需要直接添加该依赖。 你会发现spring-boot-starter其中包含了 spring-boot-starter-logging,该依赖内容就是 Spring Boot 默认的日志框架 logback。例如:spring-boot-starter-thymeleaf。

    此外,spring-boot-starter 核心Spring Boot starter,包括自动配置支持,日志和YAML等。

    2. spring boot 默认日志

    默认采用的日志是slf4j+logback,其他框架或者第三方库会通过jul-to-slf4j,log4j-to-slf4j等桥接库,将其日志重定向到slf4j,进而采用logback打印输出。

    你可能需要排除其他框架或者第三方库的原来使用的日志实现(因为他们可能在他们的pom依赖中添加了编译/打包范围的日志实现依赖(例如:log4j2,springboot的starter组件配置依赖时默认排除了springboot框架使用的common-logging日志框架)。

    3. 需不需要修改默认日志

    不需要,强烈建议,除非有不可抗拒的原因(不会有的,别想了)。

    4. spring boot 如何自定义日志配置项

    常用选项:

    logging.exception-conversion-word  LOG_EXCEPTION_CONVERSION_WORD  The conversion word used when logging exceptions.
    
    logging.file  LOG_FILE  If defined, it is used in the default log configuration.
    
    logging.file.max-size  LOG_FILE_MAX_SIZE  Maximum log file size (if LOG_FILE enabled). (Only supported with the default Logback setup.)
    
    logging.file.max-history  LOG_FILE_MAX_HISTORY  Maximum number of archive log files to keep (if LOG_FILE enabled). (Only supported with the default Logback setup.)
    
    logging.path  LOG_PATH  If defined, it is used in the default log configuration.
    
    logging.pattern.console  CONSOLE_LOG_PATTERN  The log pattern to use on the console (stdout). (Only supported with the default Logback setup.)
    
    logging.pattern.dateformat  LOG_DATEFORMAT_PATTERN  Appender pattern for log date format. (Only supported with the default Logback setup.)
    
    logging.pattern.file  FILE_LOG_PATTERN  The log pattern to use in a file (if LOG_FILE is enabled). (Only supported with the default Logback setup.)
    
    logging.pattern.level  LOG_LEVEL_PATTERN  The format to use when rendering the log level (default %5p). (Only supported with the default Logback setup.)
    

      

  • 相关阅读:
    logstash 抓取IIS日志文件写入Elasticsearch
    logstash filter geoip 转换IP为详细地址等内容。
    windows2012 iis配置
    REST接口规范
    windows10后台启动redis
    Docsify生成文档网站
    IDEA类和方法注释自动生成(2019-08-31 21:47写)
    键盘注释
    使用git上传项目解决码云文件次数上传限制(2019-09-25 12:49编写)
    Electron之Hello world(一)
  • 原文地址:https://www.cnblogs.com/pengyusong/p/11084576.html
Copyright © 2011-2022 走看看