日志打印配置示例:标签:%-,License,mm,Spring,dd,打印,msg%,日志 From: https://www.cnblogs.com/sensenh/p/16805305.html
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2010-2011 The myBatis Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<springProperty scope="context" name="LOG_HOME" source="logging.path"/>
<!-- 控制台输出 -->
<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} %-5level [%thread] %C[%L] ==> %msg%n</pattern>
<!-- <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> -->
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/info.%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>7</MaxHistory>
<!--控制所有归档日志文件的总大小-->
<totalSizeCap>500MB</totalSizeCap>
<!--是否在应用启动的时候删除历史日志-->
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} %C[%L] - %msg%n</pattern>
</layout>
</appender>
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名--> //dd格式表示每天生成一次日志文件,mm格式表示每分钟生成一次日志文件,此时如果MaxHistory是7的话,就是清除7分钟之前的日志。
<FileNamePattern>${LOG_HOME}/error.%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数--> //七天前的日志每天会清除一次
<MaxHistory>7</MaxHistory>
<!--控制所有归档日志文件的总大小--> //日志总文件大小不超过500MB
<totalSizeCap>500MB</totalSizeCap>
<!--是否在应用启动的时候删除历史日志-->
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} %C[%L] - %msg%n</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 日志输出级别 -->
<root level="ERROR">
<appender-ref ref="STDOUT"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="FILE"/>
</root>
<!--日志异步到数据库 -->
<!-- <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
日志异步到数据库
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
连接池
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
<user>root</user>
<password>root</password>
</dataSource>
</connectionSource>
</appender> -->
</configuration>
https://blog.csdn.net/u012723183/article/details/107685109