Spring Boot使用slf4j+logback記錄日誌配置詳解
本文主要介紹了Spring Boot 使用slf4j+logback記錄日誌配置,下面本站小編帶大家一起來看看詳細內容,希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試網!
學習新的東西最好從例子開始,只看文檔太枯燥,但是文檔還是必須要看的。
spring boot主要的目的是:
爲 Spring 的`開發提供了更快更廣泛的快速上手
使用默認方式實現快速開發
提供大多數項目所需的非功能特性,諸如:嵌入式服務器、安全、心跳檢查、外部配置等
SLF4J是爲各種loging APIs提供一個簡單統一的接口,從而使得最終用戶能夠在部署的時候配置自己希望的loging APIs實現。 Logging API實現既可以選擇直接實現SLF4J接的loging APIs如: NLOG4J、SimpleLogger。也可以通過SLF4J提供的API實現來開發相應的適配器如Log4jLoggerAdapter、JDK14LoggerAdapter。
Logback是由log4j創始人Ceki Gülcü設計的又一個開源日誌組件。logback當前分成三個模塊:logback-core,logback- classic和logback-access。
在src文件內新建文件配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/"/>
<logger name="" level="WARN"/>
<appender name="dailyRollingFileAppender" class="ingFileAppender">
<File>D:logs</File>
<rollingPolicy class="BasedRollingPolicy">
<!-- daily rollover 保存歷史記錄到這個文件夾一日起爲後綴 -->
<FileNamePattern>D:logstempspringboot-log.%d{yyyy-MM-dd}</FileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<Pattern>%d{HH:mm:} [%thread] %-5level %logger{35} - %msg %n</Pattern>
<charset>UTF-8</charset> <!-- 此處設置字符集 -->
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="dailyRollingFileAppender"></appender-ref>
</root>
對項目進行打包運行項目,在設置的目錄下生成日誌文件:
如果需要對logback進行其他配置還需查閱官方文檔。
如果配置好之後查看目標目錄沒有生成日誌,則是配置文件沒有複製到指定的目錄。將配置文件複製到生成的目標文件下的classes目錄下即可(targetclasses)。
相關文章
-
Spring Boot如何實現日誌記錄SLF4J
Spring Boot如何實現日誌記錄SLF4J?下面本站小編帶大家一起來看看詳細內容,希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試網!在開發中打印內容,使用 tln() 和 Log4j 應當是人人皆知的方法了。其 -
whats your plan for dragon boat festival英語作文
As a chinese, I was really ashamed of having a little knowledge of dragon boat festival. Perhaps I was bo in northe city, though my city is nearby sea, it has been built a U port which I can only see -
Urban Food Foraging Looks Fruitful美文欣賞
Foraging for food in urban areas is on the rise. Not dumpster diving. Collecting fruits and herbs.Throughout cities, forgotten fruit trees still produce, well, produce. For example, there was a peach -
Diaspora Finance Powers Global Development美文欣賞
Diaspora Finance Powers Global DevelopmentLuis Lopez-Ramirez, a 30-year old Honduran immigrant, makes pizza.He has worked two jobs over 16 hours each day.He carefully saves his money and rents a small -
Passage Eighteen (Strictly Ban smoking)英語閱讀理解
英語閱讀理解100篇(基礎篇)-18Passage Eighteen (Strictly Ban smoking)If you smoke and you still don’t believe that there’s a definite link between smoking and bronchial troubles, heart disease and lung -
Why Public Speaking Is So Important 公共演說的重要性大學英語
Many students ask why they shouldlea to give speeches. They often argue that they don’t plan to bepoliticians, members of board, or company presidents. Students think that those are the only careers -
英語作文:大學生村官 College Graduates Work as Village Offic
時間就如同白駒過隙般的流逝,前方等待着我們的是新的機遇和挑戰,是時候靜下心來好好寫寫計劃了。那麼你真正懂得怎麼制定計劃嗎?以下是小編整理的學校心理健康教育工作計劃,希望對大家有所幫助。學校心理健康教育工作計劃 -
Food and place of interest in Beijing國中英語作文
Hello,welcome to Beijing a chinese ,I am gald to tell you something about Beijing. Now, please quite and listen me Do you know Beijing Roast Duck is so delicious that people all over the world like -
描寫飛機的英語作文:the largest carbon footprint
The delegates meeting in Bonn, Germany next week for the U.N. climate conference recognize this. The lion’s share of greenhouse gas emissions from the COP23 conference, the organizers note, is f -
詳解Spring Boot Redis集成配置
spring Boot 熟悉後,集成一個外部擴展是一件很容易的事,集成Redis也很簡單,以下是本站小編搜索整理的關於詳解Spring Boot Redis集成配置,供參考學習,希望對大家有所幫助!想了解更多相關信息請持續關注我們應屆畢業生考試