springboot中引入日志文件生成的配置詳解
配置過程如下
引入依賴
<!--web啟動器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.2</version> </dependency>
提示:你沒看錯,只需要引入這一個
文件引入
在resources下邊創(chuàng)建logback-spring.xml文件
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="10 seconds" debug="false"> <!--定義日志文件的存儲地址 --> <property name="LOG_HOME" value="e:/IDEA_code/empback/src/main/logs" /> <!--<property name="COLOR_PATTERN" value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta( %replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''})- %gray(%msg%xEx%n)" />--> <!-- 控制臺輸出 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化輸出:%d表示日期,%thread表示線程名,%-5level:級別從左顯示5個字符寬度%msg:日志消息,%n是換行符 --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern> </encoder> </appender> <!-- 按照每天生成日志文件 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!--日志文件輸出的文件名 --> <FileNamePattern>${LOG_HOME}/empback-%d{yyyy-MM-dd}.%i.log</FileNamePattern> <!--日志文件保留天數(shù) --> <MaxHistory>30</MaxHistory> <maxFileSize>20MB</maxFileSize> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化輸出:%d表示日期,%thread表示線程名,%-5level:級別從左顯示5個字符寬度%msg:日志消息,%n是換行符 --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern> </encoder> </appender> <!-- 生成 error html格式日志開始 --> <appender name="HTML" class="ch.qos.logback.core.FileAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <!--設(shè)置日志級別,過濾掉info日志,只輸入error日志--> <level>ERROR</level> </filter> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="ch.qos.logback.classic.html.HTMLLayout"> <pattern>%p%d%msg%M%F{32}%L</pattern> </layout> </encoder> <file>${LOG_HOME}/error-log.html</file> </appender> <!-- 生成 error html格式日志結(jié)束 --> <!-- 每天生成一個html格式的日志開始 --> <appender name="FILE_HTML" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!--日志文件輸出的文件名 --> <FileNamePattern>${LOG_HOME}/empback-%d{yyyy-MM-dd}.%i.html</FileNamePattern> <!--日志文件保留天數(shù) --> <MaxHistory>30</MaxHistory> <MaxFileSize>10MB</MaxFileSize> </rollingPolicy> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="ch.qos.logback.classic.html.HTMLLayout"> <pattern>%p%d%msg%M%F{32}%L</pattern> </layout> </encoder> </appender> <!-- 每天生成一個html格式的日志結(jié)束 --> <!--myibatis log configure --> <logger name="com.apache.ibatis" level="TRACE" /> <logger name="java.sql.Connection" level="DEBUG" /> <logger name="java.sql.Statement" level="DEBUG" /> <logger name="java.sql.PreparedStatement" level="DEBUG" /> <!-- 日志輸出級別 --> <root level="INFO"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> <appender-ref ref="HTML" /> <appender-ref ref="FILE_HTML" /> </root> </configuration>
小結(jié)
啟動就可以了
注意文件路徑只指定你自己的
<property name="LOG_HOME" value="e:/IDEA_code/empback/src/main/logs" />
到此這篇關(guān)于springboot中引入日志文件生成的配置詳解的文章就介紹到這了,更多相關(guān)springboot引入日志文件配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
教你使用springSecurity+jwt實現(xiàn)互踢功能
JWT作為一個開放的標(biāo)準(zhǔn)( RFC 7519 ),定義了一種簡潔的,自包含的方法用于通信雙方之間以Json對象的形式安全的傳遞信息。接下來通過本文給大家介紹springSecurity+jwt實現(xiàn)互踢功能,需要的朋友可以參考下2021-11-11SpringBoot實現(xiàn)application配置信息加密
在配置文件中,我們有開發(fā)環(huán)境配置和生產(chǎn)環(huán)境配置,而生產(chǎn)環(huán)境的配置信息是需要做好防護的,避免外泄,所以本文為大家整理了application配置信息加密的方法,需要的可以參考下2023-07-07SpringSecurity自定義登錄接口的實現(xiàn)
本文介紹了使用Spring Security實現(xiàn)自定義登錄接口,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01mybatis-plus-boot-starter包與mybatis-plus-generator的沖突解決
本文主要介紹了mybatis-plus-boot-starter包與mybatis-plus-generator的沖突解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-10-10Springboot ApplicationRunner的使用解讀
這篇文章主要介紹了Springboot ApplicationRunner的使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05