春季启动战争log4j2 [英] spring boot war log4j2

查看:90
本文介绍了春季启动战争log4j2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot版本1.3.5(Spring 4.2.6)开发应用程序. 我使用log4j2版本2.4.1作为记录系统. 在sts(春季工具套件)上工作并在嵌入式tomcat上执行时,日志工作正常(在控制台和文件上),但是在构建war文件并将其部署到外部tomcat 8上时,会创建日志文件,但我的日志却没有出现在其中.

我一直在寻找类似的问题,并测试了一些解决方案:

  1. 在tomcat上设置logging.config属性
  2. 使用参数logging.config = classpath:log4j2-spring.xml配置"application.properties"文件
  3. 使用其他日志记录框架(logback)

,但此解决方案均无效. 讨论该问题的帖子是: 配置为.war 时的Spring-Boot日志记录配置

请提供任何帮助或详细的答案.

解决方案

如果您想在Tomcat中为Spring Boot应用程序配置log4j,则本文档可能会为您提供帮助:

https://tomcat.apache.org/tomcat-8.5- doc/logging.html#Using_Log4j

使用Log4j

本节介绍如何配置Tomcat以使用log4j而不是 java.util.logging用于所有Tomcat的内部日志记录.

注意:当您要执行以下操作时,需要执行本节中描述的步骤 重新配置Tomcat以使用Apache log4j进行自己的日志记录.这些 如果您只想在自己的网站中使用log4j,则无需执行任何步骤 应用. —在这种情况下,只需将log4j.jarlog4j.properties进入您的WEB-INF/libWEB-INF/classes 网络应用程序.

以下步骤描述了配置log4j以输出Tomcat的 内部记录.

创建一个名为log4j.properties的文件,其内容如下: 将其保存到$CATALINA_BASE/lib

i'm developing a application using spring boot version 1.3.5 (spring 4.2.6). i use log4j2 version 2.4.1 as logging system. when working on sts (spring tool suite) and executing on embeeded tomcat, the logs works fine (on console and on file) but when building a war file and deploying it on external tomcat 8 the log file is created but my logs don't appear in it.

i've looked for similar issue and tested some solutions:

  1. setting the logging.config property on tomcat
  2. configuring 'application.properties' file with the parameter logging.config=classpath:log4j2-spring.xml
  3. using another logging framework (logback)

but none of this solution work. the post that talks about that is: Spring-Boot Logging configuration when deployed as .war

any help or detailled answer please.

解决方案

If you want to configure log4j for your Spring Boot application inside Tomcat, this documentation may help you :

https://tomcat.apache.org/tomcat-8.5-doc/logging.html#Using_Log4j

Using Log4j

This section explains how to configure Tomcat to use log4j rather than java.util.logging for all Tomcat's internal logging.

Note: The steps described in this section are needed when you want to reconfigure Tomcat to use Apache log4j for its own logging. These steps are not needed if you just want to use log4j in your own web application. — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application.

The following steps describe configuring log4j to output Tomcat's internal logging.

Create a file called log4j.properties with the following content and save it into $CATALINA_BASE/lib

这篇关于春季启动战争log4j2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆