在log4j xml配置中使用系统环境变量 [英] Using system environment variables in log4j xml configuration

查看:4283
本文介绍了在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?

我想要能够例如:

<level value="${env.LOG_LEVEL}" />

并让它从系统环境变量中获取,所以我可以避免传入这么多

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配置中使用系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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