您好,登錄后才能下訂單哦!
SpringBoot中怎么實(shí)現(xiàn)一個(gè)slf4j日志功能,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
其pom.xml里的依賴(lài)定義如下:
上圖看到很多Starter,比如Spring-boot-starter-data-redis, Spring-boot-starter-web等等。這些Starter都包含了一個(gè)spring-boot-starter, 而這個(gè)starter又包含了一個(gè)實(shí)現(xiàn)logging的starter,叫做spring-boot-starter-logging.
也就是說(shuō),如果我們使用SpringBoot,無(wú)需再導(dǎo)入額外的配置,就能使用日志功能了。
SpringBoot slf4j的默認(rèn)實(shí)現(xiàn)是logback,默認(rèn)輸出是到控制臺(tái)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)目全局的日志級(jí)別:
當(dāng)然要針對(duì)個(gè)別包進(jìn)行日志級(jí)別的分別配置也是可以的:
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.
將日志寫(xiě)入本地日志文件的做法:
關(guān)于SpringBoot中怎么實(shí)現(xiàn)一個(gè)slf4j日志功能問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。