我将 log4j2(版本 2.10.0)与 IBM Websphere 8.5.5.12 一起使用。
问题是我的 log4j2.properties 中的 Websphere 环境变量没有得到解决。我尝试过一些事情,比如
property.filename = $${sys:Test}/Test.log
property.filename = ${env:Test}/Test.log
但无论我尝试什么,它都没有解决“测试”问题。谁能帮我解决这个问题?
最佳答案
如果您在正确的资源范围内创建了可供 JVM 访问的变量,则可以通过添加与 Websphere 环境变量同名的 JVM 自定义属性和如下给出的值来解决此问题:
Steps : In WAS Admin console, Go to
WebSphere application servers >
Server_name >
Java and Process Management (under Server Infrastructure)>
Process definition >
Java Virtual Machine (under Additional Properties)>
Custom properties
Click on New and enter below details :
Name : Test
Value : ${Test}
Apply and save the changes.
重新启动 JVM 并重新测试!
编辑:正如下面的评论中提到的,添加JVM自定义属性后,可以直接从log4j文件访问该变量,如下所示:
property.filename = ${Test}/Test.log
关于java - log4j2查找websphere环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49067429/