Python 官方文档:入门教程 => 点击学习
前言 本文详细介绍如何使用spring-boot2.x快速整合log4j2日志框架。 spring-boot2.x使用logback作为默认日志处理库,因此我们除了要引用log4j
本文详细介绍如何使用spring-boot2.x快速整合log4j2日志框架。
spring-boot2.x使用logback作为默认日志处理库,因此我们除了要引用log4j2之外,还要去除logback的依赖
Maven方式:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
去除冲突依赖
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
配置文件路径
配置文件放在根目录或者resource目录都可以,也可以在application.properties中配置指定路径:
logging.config=classpath:log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<!--添加一个控制台追加器-->
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout>
<pattern>[%-5p] %d %c - %m%n</pattern>
</PatternLayout>
</Console>
<!--添加一个文本追加器,文件位于根目录下,名为log.log-->
<File name="File" fileName="logs/log.log">
<PatternLayout>
<pattern>[%-5p] %d %c - %m%n</pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="Console" />
</Root>
<!--把org.springframework包下的所有日志输出到log文件,additivity="false"表示不输出到控制台-->
<Logger name="org.springframework" level="DEBUG" additivity="true">
<AppenderRef ref="File" />
</Logger>
</Loggers>
</Configuration>
到此为止,我们就已经将log4j2应用到了SpringBoot中,是不是很简单。
到此这篇关于springboot2.x只需两步快速整合log4j2的方法的文章就介绍到这了,更多相关springboot2.x整合log4j2内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: springboot2.x只需两步快速整合log4j2的方法
本文链接: https://www.lsjlt.com/news/125053.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0