<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="30 seconds"> <contextName>server</contextName> <!--日志路径 --> <property name="LOG_HOME" value="${LOG_HOME}" /> <!-- 日志文件输出 --> <appender name="rollingFileOut" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Encoding>UTF-8</Encoding> <prudent>true</prudent> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_HOME}/auto-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <maxHistory>30</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy><!-- --> <!-- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>0.1MB</MaxFileSize> </triggeringPolicy> --> </rollingPolicy> <encoder><!-- 暂时先使用原有格式 --> <pattern>%date %level [%thread] %logger.%class{0}#%method [%file:%line] %msg%n</pattern> <charset>GBK</charset> </encoder> </appender> <!-- 定义控制台输出 --> <appender name="consoleOut" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date %level [%thread] %logger.%class{0}#%method [%file:%line] %msg%n</pattern> </encoder> </appender> <!-- <logger name="App"> <appender-ref ref="rollingFileOut" /> </logger> --> <logger name="org.apache.ibatis.io.ResolverUtil" level="WARN"/> <logger name="org.mybatis.spring.SqlSessionUtils" level="WARN"/> <logger name="org.mybatis.spring.SqlSessionFactoryBean" level="WARN"/> <logger name="org.mybatis.spring.transaction.SpringManagedTransaction" level="WARN"/> <logger name="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" level="WARN"/> <logger name="org.springframework.jdbc.datasource.DataSourceTransactionManager" level="WARN"/> <logger name="org.springframework.jdbc.datasource.DataSourceUtils" level="WARN"/> <logger name="org.springframework.scheduling.quartz.LocalDataSourceJobStore" level="WARN"/> <logger name="org.quartz.impl.jdbcjobstore.StdRowLockSemaphore" level="WARN"/> <logger name="org.apache.http.wire" level="WARN"/> <root level="debug"><!-- TRACE, DEBUG, INFO, WARN, ERROR, ALL, OFF --> <appender-ref ref="consoleOut" /> <!--部署到服务器上时要注释掉 --> <appender-ref ref="rollingFileOut" /> </root> </configuration>
优点:可以打印输出debug级别的sql语句等信息,而过滤掉一些jar包的无关日志(level="WARN"),避免日志文件过于庞大。
时间: 2024-11-02 01:37:04