您现在的位置是:首页 > 文章详情

SpringBoot里slf4j日志功能的默认实现

日期:2020-02-26点击:380

本文是这篇教程的学习笔记:
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.

将日志写入本地日志文件的做法:

本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

原文链接:https://yq.aliyun.com/articles/746754
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章