SpringBoot里slf4j日志功能的默认实现
本文是这篇教程的学习笔记:
https://www.springboottutorial.com/logging-with-spring-boot-logback-slf4j-and-log4j
我有一个最简单的SpringBoot应用,其pom.xml里的依赖定义如下:
上图看到很多Starter,比如Spring-boot-starter-data-redis, Spring-boot-starter-web等等。这些Starter都包含了一个spring-boot-starter, 而这个starter又包含了一个实现logging的starter,叫做spring-boot-starter-logging.
也就是说,如果我们使用SpringBoot,无需再导入额外的配置,就能使用日志功能了。
SpringBoot slf4j的默认实现是logback,默认输出是到控制台console:
As you can see the default logging framework is Logback with SLF4j as implementation.
By default, all logging goes to console.
在Application.properties文件里使用logging.level.root配置项目全局的日志级别:
当然要针对个别包进行日志级别的分别配置也是可以的:
logging.level.some.package.path=DEBUG
logging.level.some.other.package.path=ERROR
Custom configuration using logback.xml
Spring Boot will pick up all custom configuration using logback.xml as long as it is in the application class path.
将日志写入本地日志文件的做法:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- 使用SpringBoot AOP 记录操作日志、异常日志
- 基于SpringBoot的多模块项目引入其他模块时@Autowired无法注入其他模块stereotype注解类对象的问题解决
- SpringBoot里实现了某个接口的实现类运行时如何注入的?
- Springboot调度任务:动态管理
- 使用Maven的父项目,多个子模块来开发Springboot项目,新建的子模块如何和同级的子模块进行依赖
- 【springboot】14、拦截器Interceptor
- SpringBoot整合Druid
- springboot注解
- SpringBoot默认日志logback配置解析
- 项目构建之springboot集成lomback.xml,和log4j基于properties方式的日志配置记录
- springboot日志的实现方式(两种log4j2.properties和log4j2.yml)
- SpringBoot日志配置