简体   繁体   中英

log4j2 lookup websphere environment variable

I'm using log4j2 (version 2.10.0) together with IBM Websphere 8.5.5.12.
The problem is that the Websphere environment variable in my log4j2.properties is not getting resolved. I've tried a few things like

property.filename = $${sys:Test}/Test.log
property.filename = ${env:Test}/Test.log

But whatever i try, it is not resolving "Test". Anyone who can help me with this?

If you have the variable created at the right resource scope, accessible by your JVM, this can be fixed by adding a JVM custom property with the same name as the Websphere environment variable and value as given below:

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.

Restart the JVM and retest !

EDIT : As mentioned in the comment below, after adding the JVM custom property, the variable can be directly accessed from log4j file, as given below:

property.filename = ${Test}/Test.log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM