SpringBoot加入Log4j2

必须承认,对这些我都是一知半解。

依照网上操作,加入Log4j2,

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除框架中的logback依赖 -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>

</dependency>
<!-- log4j2 1.3.x以上版本只支持log4j2 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

applications.yml文件中添加:

logging:
  config: classpath:log4j2.xml
  level: info

启动报错:

2019-08-08 11:08:23,798 restartedMain INFO Log4j appears to be running in a Servlet environment, but there's no log4j-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringBoot中使用Log4j2需要进行以下配置: 1. 在application.properties或application.yaml文件中指定日志配置文件的位置。可以使用以下配置:logging.config=classpath:log4j2.xml。 2. 在项目的依赖中添加Spring Boot Starter Log4j2的依赖项。可以通过在pom.xml文件中添加以下依赖项来实现: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> ``` 3. 需要在依赖中排除logback,因为在使用Log4j2时与其冲突。同时也需要排除log4j-to-slf4j适配器,因为它与Spring Boot Starter自带的log4j-to-slf4j相互冲突。可以使用以下配置来实现:[3] ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> </exclusion> </exclusions> </dependency> ``` 这样就可以在SpringBoot项目中使用Log4j2进行日志记录了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [【Spring】SpringBoot 配置 log4j2 日志](https://blog.csdn.net/qq_27198345/article/details/128310211)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [SpringBoot 项目中使用Log4j2详细(避坑)](https://blog.csdn.net/RyanDon/article/details/82589989)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值