SpringBoot下使用LogBack打印日志,按天生成,存放指定数量日志
程序员文章站
2022-03-05 08:07:41
...
1.application.yml 加入配置
logging:
config: classpath:logback.xml
level:
root: INFO
org.hibernate: INFO
org.hibernate.type.descriptor.sql.BasicExtractor: INFO
com.ys.adage.mapper: INFO
org.springframework: INFO
2.logback 配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="rollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/logs/bdService.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/bdService.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>10</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="com.ys.adage.mapper" level="info" additivity="false">
<appender-ref ref="rollingFile"/>
</logger>
<appender name="async-stdout" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="stdout"/>
<includeCallerData>true</includeCallerData>
</appender>
<appender name="async-rollingFile" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="rollingFile"/>
<includeCallerData>true</includeCallerData>
</appender>
<logger name="com.ibatis" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" />
<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" />
<logger name="java.sql.Connection" level="DEBUG" />
<logger name="java.sql.Statement" level="DEBUG" />
<logger name="java.sql.PreparedStatement" level="DEBUG" />
<logger name="org.quartz.impl.jdbcjobstore.JobStoreTX" level="INFO"/>
<logger name="org.quartz.impl.jdbcjobstore.StdRowLockSemaphore" level="INFO"/>
<logger name="org.springframework.amqp.rabbit.core.RabbitTemplate" level="INFO"/>
<logger name="org.springframework.amqp.rabbit.listener.BlockingQueueConsumer" level="INFO"/>
<root level="INFO">
<appender-ref ref="async-stdout"/>
<appender-ref ref="async-rollingFile"/>
</root>
</configuration>
上一篇: jQuery使用EasyUi实现三级联动下拉框效果实例分享
下一篇: Logback例子