Spring boot logging

Spring boot logging

源码

源码链接 https://gitee.com/mayun_xiaodu/spring-boot-all

上一节 Spring boot 配置文件读取和yaml结构

Spring boot 配置文件读取和yaml结构


首先我们搭一个web工程,集成spring-boot-starter-web;spring-boot-starter-web中依赖了spring-boot-starter-logging;
启动springboot

springboot 启动日志

springboot 提供的默认输出日志


 .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
 '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v2.1.6.RELEASE)

2021-03-29 09:55:06.451  INFO 80640 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-03-29 09:55:06.473  INFO 80640 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-03-29 09:55:06.473  INFO 80640 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.21]
2021-03-29 09:55:06.566  INFO 80640 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-03-29 09:55:06.566  INFO 80640 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1249 ms
2021-03-29 09:55:06.753  INFO 80640 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-29 09:55:06.882  INFO 80640 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

自定义logging

(这里使用 slf4j + logback 进行示例)

1.配置文件中设置日志参数
logging:
  level:
    root: info   # 配置root 的级别
    com.xiaodu.springboot.logging: warn # 配置具体包下的日志级别
  file:
    max-size: 10KB
    max-history: 7
  path: logging-logs
  pattern:
    ## %d{日期格式}  %level 日志级别  %t 线程  %logger{length} logger名 %m 日志内容 %L 日志输出的行数, %n 换行;
    console: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [%15t] %logger{20} => %m Line: %L%n'

代码中输出日志

  // 进行日志输出
        log.trace
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值