首页 > 其他分享 >Spring日志打印配置

Spring日志打印配置

时间:2022-10-19 10:35:27浏览次数:65  
标签:%- License mm Spring dd 打印 msg% 日志

日志打印配置示例:

<?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

标签:%-,License,mm,Spring,dd,打印,msg%,日志
From: https://www.cnblogs.com/sensenh/p/16805305.html

相关文章

  • JPA入门学习集合springboot(一)
    1、在pom.xml文件中添加相应依赖SpringDatajpa和数据库MySql<!--SpringDataJPA依赖(重要)--><dependency><groupId>org.springframework.boo......
  • 个人理解【一】【Spring Security5.7】
    1.SpringSecurity的默认实现分析根据url分配到不同的Filter。UsernamePasswordAuthenticationFilter对默认的表单登录进行处理BasicAuthenticationFilter对HttpB......
  • winfrom 中配置log4日志
    一、下载log4net组件直接引入log4net.dll文件到引用,或者使用NuGet,搜索log4net下载到项目中  二、创建配置一个log4net.config文件(将此文件属性设置为:始终复制),文件内......
  • 解决Vue打印el-table不完全的pdf问题
    智能中医项目中的打印报告要新增一项异常检测表格的显示,纸张定为A4纸张竖向打印,在使用el-table后发现,虽然页面中显示无误,但不管怎么样设置table的宽度,打印的pdf中最后一列......
  • SpringBoot自定义Banner信息
    SpringBoot自定义Banner信息一、介绍本文主要介绍使用springboot框架时,我们可以自定义我们项目的相关信息,例如启动图、启动时的版本号等。二、自定义banner我们在启......
  • Elasticsearch SpringBoot 整合 ES 测试保存
    一、修改Config官方文档:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-low-usage-requests.html#java-rest-low-usage-request-option......
  • 04.大型数据库应用技术课堂测试05-日志数据分析-错误总结
    错误总结:1.ExpressionnotinGROUPBYkey'id'解决:在groupby子句中,select查询的列,要么需要是groupby中的列,要么得是用聚合函数(比如sum、count等)加工过的列。不......
  • SpringBoot
    了解SpringBoot:https://blog.csdn.net/Delia_theme/article/details/88681722学习文档:http://c.biancheng.net/spring_boot/example.htmlspringboot狂神笔记:https://blog......
  • Elasticsearch SpringBoot 整合 ES
    一.ES的JavaAPI两种方式  Elasticsearch的API分为RESTClientAPI(http请求形式)以及transportClientAPI两种。相比来说transportClientAPI效率更高,transportCli......
  • 记录清理Oracle归档日志
    一、登录数据库1.切换到Oracle用户su命令–切换用户身份su命令来自于英文单词“switchuser”的缩写,其功能是用于切换用户身份。管理员切换至任意用户身份而无需密......