javascript
SpringBoot里slf4j日志功能的默认实现
本文是這篇教程的學(xué)習(xí)筆記:
https://www.springboottutorial.com/logging-with-spring-boot-logback-slf4j-and-log4j
我有一個最簡單的SpringBoot應(yīng)用,其pom.xml里的依賴定義如下:
上圖看到很多Starter,比如Spring-boot-starter-data-redis, Spring-boot-starter-web等等。這些Starter都包含了一個spring-boot-starter, 而這個starter又包含了一個實(shí)現(xiàn)logging的starter,叫做spring-boot-starter-logging.
也就是說,如果我們使用SpringBoot,無需再導(dǎo)入額外的配置,就能使用日志功能了。
SpringBoot slf4j的默認(rèn)實(shí)現(xiàn)是logback,默認(rèn)輸出是到控制臺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配置項(xiàng)目全局的日志級別:
當(dāng)然要針對個別包進(jìn)行日志級別的分別配置也是可以的:
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的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的SpringBoot里slf4j日志功能的默认实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 银行一年利息怎么算?
- 下一篇: 火炬之光2控制台洗点怎么调?控制台洗点技