Spring-boot的application.properties文件可以通过log4j2.xml进行配置吗? [英] Can spring-boot application.properties file woking with log4j2.xml configuration?

查看:210
本文介绍了Spring-boot的application.properties文件可以通过log4j2.xml进行配置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在application.properties中定义高级文件记录,以方便利用我的log4j2.xml文件配置.我的log4j2配置本身工作正常,但是我希望控制日志记录级别以及来自application.properties文件的日志文件和路径信息.我在应用程序的pom文件中具有spring-boot-starter-log4j2依赖项.

I want to define high-level file logging in application.properties as a convenience to leverage my log4j2.xml file configuration. By itself my log4j2 config is working fine, however I was hoping to control logging levels and log file and path info from the application.properties file. I have the spring-boot-starter-log4j2 dependency in the application's pom file.

在log4j2.xml中,我具有以下属性之一

In log4j2.xml I have as one of the properties

<Property name="LOG_FILE">${LOG-DIR}/test.log</Property>

,其中LOG-DIR是在同一文件的另一个(先前)属性中定义的.在我的application.properties文件中,

, where LOG-DIR is defined in another (previous) property in the same file. In my application.properties file, I have

logging.file=LOG_FILE 

作为属性,加上一些级别属性,例如

as a property, plus several level properties such as

logging.level.org.springframework.web=DEBUG

我的application.properties文件中定义的与日志相关的所有属性

都无法构建相应的日志文件.再次,当我简单地单独使用log4j2.xml时,它可以很好地工作,但是想要利用application.properties的便利性来进行日志记录配置.

none of these log-related properties as defined in my application.properties file are working to build the corresponding log file. Again, when I simply use log4j2.xml by itself it works fine, but wanted to take advantage of the convenience of application.properties for logging configuration.

任何对我做错事情的见解都将受到赞赏.谢谢

Any insights into what I am doing wrong are greatly appreciated. thank you

推荐答案

如果我正确地理解了您的问题,那么您正在看的是

If I understood your question right, you are looking at Property Substitution feature of log4j2.

您可以在 application.properties 文件中定义日志记录属性,如下所示:

You can define logging property in application.properties file like below:

log.file.path=/myDir/logpath 

然后在 log4j2.xml 中定义为 Property 的属性查找:

And then the property(s) lookup defined as Property in log4j2.xml:

<Configuration>  
  <Properties>  
      <property name="LOG_FILE">${bundle:application:log.file.path}</property> 
  </Properties>  

现在,所有属性都可以使用 $ {propertyName} 表示法在同一 log4j2.xml 中引用,该表示法最终指向 application.properties 中的值代码>文件.

Now all the property can be referred in same log4j2.xml with ${propertyName} notation, which eventually points to values from application.properties file.

这篇关于Spring-boot的application.properties文件可以通过log4j2.xml进行配置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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