Using system environment variables in log4j xml configuration(在 log4j xml 配置中使用系统环境变量)
问题描述
是否可以在 log4j xml 配置文件中引用系统环境变量(相对于 Java 系统属性)?
Is it possible to reference system environment variables (as opposed to Java system properties) in a log4j xml configuration file?
我希望能够做类似的事情:
I'd like to be able to do something like:
<level value="${env.LOG_LEVEL}" />
并让它从系统环境变量中获取,这样我就可以避免使用 -D 参数传递这么多东西.
and have it get that from the system environment variables, so I can avoid having to pass in so many things with -D parameters.
推荐答案
此语法仅记录在 log4j 2.X 中,因此请确保您使用的是正确的版本.它不适用于 1.X 版本.
This syntax is documented only in log4j 2.X so make sure you are using the correct version. It does not work on the 1.X versions.
<Appenders>
<File name="file" fileName="${env:LOG_PATH}">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>
</PatternLayout>
</File>
</Appenders>
这篇关于在 log4j xml 配置中使用系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 log4j xml 配置中使用系统环境变量
基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
