Java 如何在 log4j.properties 中使用系统环境变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22296275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:47:29  来源:igfitidea点击:

How to use system environment variables in log4j.properties?

javalog4jenvironment-variables

提问by deepaksharma

I added the system environment value PROJECT_HOME=C:\Program Files\Project

我添加了系统环境值 PROJECT_HOME=C:\Program Files\Project

Now i'm trying to use the system environment value in log4j.properties but didn't set it

现在我试图在 log4j.properties 中使用系统环境值但没有设置它

**log4j.properties**
**log4j.appender.LOGFILE.File="${env.PROJECT_HOME}"/project.log**

Could you please tell me how to set system environment variables in log4j.properties?

你能告诉我如何在 log4j.properties 中设置系统环境变量吗?

Using log4j-1.2.7 version

使用 log4j-1.2.7 版本

回答by Leos Literak

This is supported by EnvironmentLookupin log4j - 2. See examples.

log4j - 2 中的EnvironmentLookup支持此功能。请参阅示例。

Use ${sys:PROJECT_HOME}instead of ${env.PROJECT_HOME}

使用${sys:PROJECT_HOME}代替${env.PROJECT_HOME}