如何在 Websphere 中设置 log4j.properties 文件的相对路径

How to set relative path for log4j.properties file in Websphere

您好,我正在尝试将 Websphere 自定义属性下的 log4j.properties 路径设置为无效的相对路径。

设置位置:

中间件服务器 > cluster1node1 > 流程定义 > Java 虚拟机 > 自定义属性

这是有效的:

 Property name: log4j.configuration
 Value: file:/dir1/dir2/my_configs/log4j.properties

这不起作用。

 Property name: log4j.configuration 
 Value: ${CONFIG_ROOT}/my_configs/log4j.properties 

其中 config root 是一个 websphere 变量,如下所示;

 Name: CONFIG_ROOT
 Value: /dir1/dir2/

有人能告诉我我可能做错了什么吗?我能够为普通应用程序配置文件成功使用类似的相对路径。似乎此问题仅适用于 log4j.properties 文件。

最新更新:

实际上这个问题与文件系统更相关,因为当我用 file: 预先修复相对路径时它起作用了。

现在可以使用了。

 Property name: log4j.configuration 
 Value: file:${CONFIG_ROOT}/my_configs/log4j.properties 

但这是为什么呢?为什么没有 file: 就不能工作?以及如何在没有 文件的情况下使其工作:

根据this answer中解释的log4j默认初始化过程,log4j尝试将log4j.configuration的值转换为URL,因此需要文件:

这个问题更多地与文件系统有关,因为当我用 file: 预先固定相对路径时它起作用了。

现在可以使用了。

 Property name: log4j.configuration 
 Value: file:${CONFIG_ROOT}/my_configs/log4j.properties