SpringBoot使用Log4J2

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions><!-- 去掉springboot默认配置 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- 引入log4j2依赖 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
2.2 log4j2配置
<?xml version="1.0" encoding="UTF-8"?>
<!-- 主要配置为error日志与debug日志分别打印文件,errorLog按照分钟存档,debugLog按照日志文件大小存档,最多保存10个。 -->
<!-- 日志打印状态为debug, monitorInterval是用来设置配置文件的动态加载时间的,每30秒配置文件会动态加载一次,修改配置30秒会生效-->
<configuration status="debug" monitorInterval="30">
<Properties>
<!-- baseLogDir变量名,日志存储路径。logPattern日志打印路径 -->
<property name="baseLogDir">./app/log</property>
<!-- 格式化输出:%d格式化日期,%-5level:级别从左显示5个字符宽度,%thread表示线程名,%msg:日志消息,%n是换行符 -->
<property name="logPattern">%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%logger{0}:%line][%thread] %X{logger_id} - [TID: %X{EagleEye-TraceID}] %msg%n</property>
</Properties>
<Appenders>
<!--Appender 1. console输出DEBUG级别以上日志,指定输出格式和过滤器等级为DEBUG -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="${logPattern}"/>
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<!--Appender 2. INFO日志保存到app.log文件,日志留3天 -->
<RollingFile name="business" fileName="${baseLogDir}/app.log"
filePattern="${baseLogDir}/app.log.%d{yyyy-MM-dd}">
<PatternLayout pattern="${logPattern}"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<DefaultRolloverStrategy>
<Delete basePath="${baseLogDir}" maxDepth="2">
<IfFileName glob="app.log.20*" />
<IfLastModified age="3d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--Appender 3. DEBUG日志保存到debug.log文件,日志留3天 -->
<RollingFile name="debug" fileName="${baseLogDir}/debug.log"
filePattern="${baseLogDir}/debug.log.%d{yyyy-MM-dd}">
<PatternLayout pattern="${logPattern}"/>
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<DefaultRolloverStrategy>
<Delete basePath="${baseLogDir}" maxDepth="2">
<IfFileName glob="debug.log.20*" />
<IfLastModified age="3d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<!--Appender 4. ERROR日志保存到error.log文件,日志留3天 -->
<RollingFile name="error" fileName="${baseLogDir}/error.log"
filePattern="${baseLogDir}/error.log.%d{yyyy-MM-dd}">
<PatternLayout pattern="${logPattern}"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<DefaultRolloverStrategy>
<Delete basePath="${baseLogDir}" maxDepth="2">
<IfFileName glob="error.log.20*" />
<IfLastModified age="3d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<AsyncRoot level="info" includeLocation="true">
<AppenderRef ref="console"/>
<AppenderRef ref="business"/>
<AppenderRef ref="debug"/>
<AppenderRef ref="error"/>
</AsyncRoot>
</Loggers>
</configuration>
SpringBoot使用Log4J2的更多相关文章
- Springboot整合log4j2日志全解
目录 常用日志框架 日志门面slf4j 为什么选用log4j2 整合步骤 引入Jar包 配置文件 配置文件模版 配置参数简介 Log4j2配置详解 简单使用 使用lombok工具简化创建Logger类 ...
- SpringBoot整合log4j2进行日志配置及防坑指南
写在前面 最近项目经理要求将原先项目中的日志配置logBack,修改为log4j2,据说是log4j2性能更优于logback,具体快多少,网上有说快10多倍,看来还是很快的,于是新的一波挑战又开始了 ...
- 第三篇 SpringBoot整合log4j2详解
源代码:https://pan.baidu.com/s/1d1Lwv1gIvVNltIKVWeEseA 提取码:wff0 SpringBoot整合Log4j2步骤: 1.删除spring-boot-s ...
- springboot logback + log4j2日志管理
springboot的web项目中自带了日志组件: 我们看一下,springboot中找到日志组件. <dependency> <groupId>org.springframe ...
- Springboot + SLF4j + Log4j2 打印异常日志时,耗时要5-6秒
1.使用jps -l 查看springboot项目的进程ID 2.使用命令jstack -l 进程ID > log.txt 打印堆栈信息到文件,内容如下: "http-nio-8065 ...
- 十一、springboot 配置log4j2以及打包成zip文件
前言 其实我们前面已经配置了日志,但是最近总感觉日志日志格式看的不舒服,并且每次打包都是一个jar 文件,lib都包含在jar 中,每次做很小的修改都需要重新替换jar文件,jar文件会比较大,传输起 ...
- SpringBoot整合log4j2导入新的依赖出现jar冲突解决
1.问题复现: 之前在SpringBoot中配置整合了log4j2,今天在pom文件中,导入新的依赖(依赖如下)之后, <dependency> <groupId>com.gi ...
- springboot整合log4j2遇到的一个坑
背景 项目中使用springboot,需要用log4j2做日志框架 问题 项目启动报错:Could not initialize Log4J2 logging from classpath:log4j ...
- SpringBoot—整合log4j2入门和log4j2.xml配置详解
关注微信公众号:CodingTechWork,一起学习进步. 引言 对于一个线上程序或者服务而言,重要的是要有日志输出,这样才能方便运维.而日志的输出需要有一定的规划,如日志命名.日志大小,日志分 ...
- Springboot整合log4j2【详细步骤】
1.去除logback中的依赖包 <dependency> <groupId>org.springframework.boot</groupId> <arti ...
随机推荐
- python之高级数据结构Collections
1. Collections collections模块包含了内建类型之外的一些有用的工具,例如Counter.defaultdict.OrderedDict.deque以及nametuple.其中C ...
- getent使用小结
转载请注明出处: getent 是一个用于访问系统数据库的命令,通常用于获取与网络有关的信息,比如用户.组.主机名.服务等.这个命令是 Linux 和 Unix 系统中非常有用的工具,可以用来查询多种 ...
- CCPC Henan Provincial Contest 2020
CCPC Henan Provincial Contest 2020 Problem B. 广告投放 n集节目按顺序播出,节目组决定在某些节目中投放广告,节目最初播出时有m名观众,若\(i\)集投放广 ...
- 新型大语言模型的预训练与后训练范式,苹果的AFM基础语言模型
前言:大型语言模型(LLMs)的发展历程可以说是非常长,从早期的GPT模型一路走到了今天这些复杂的.公开权重的大型语言模型.最初,LLM的训练过程只关注预训练,但后来逐步扩展到了包括预训练和后训练在内 ...
- Flutter Package: retry
Flutter package: retry 传送门 This package provides an easy way to retry asynchronous functions. This i ...
- Python的OCR工具pytesseract解决TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information环境变量问题
pytesseract是基于Python的OCR工具, 底层使用的是Google的Tesseract-OCR 引擎,支持识别图片中的文字,支持jpeg, png, gif, bmp, tiff等图片格 ...
- Qt编写可视化大屏电子看板系统29-模块7品质管理
一.前言 品质管理模块是在送检合格模块的基础上增加了统计而来,总共包括了三个子模块:品质占比.班组合格率.每日合格率统计,其中品质占比子模块采用饼图控件显示对应的百分比,不同百分比颜色不一样,这个饼图 ...
- Mac系统Obsidian和Typora更换霞鹜文楷字体
在github上发现了一款非常好看的字体LXGW WenKai / 霞鹜文楷,这里记录下Mac电脑如何安装这个字体,以及我用到的笔记软件更换字体的过程. Mac安装字体 # 增加代理,不加代理下载速度 ...
- [转]Spring Security打造一个简单Login登录页面,实现登录+跳转+注销+角色权限功能,核心代码不到100行!
原文链接:Spring Security打造一个简单Login登录页面,实现登录+跳转+注销+角色权限功能,核心代码不到100行!
- [转]fatal: remote error: The unauthenticated git protocol on port 9418 is no longer support问题解决
背景 因为居家办公,把代码从远程clone下来之后,发现使用npm install一直失败. 提示的错误:fatal: remote error: The unauthenticated git pr ...