SpringBoot中怎么实现一个slf4j日志功能

2023-05-16,

SpringBoot中怎么实现一个slf4j日志功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

其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.

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

关于SpringBoot中怎么实现一个slf4j日志功能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注本站行业资讯频道了解更多相关知识。

《SpringBoot中怎么实现一个slf4j日志功能.doc》

下载本文的Word格式文档,以方便收藏与打印。