Loading
Salesforce now sends email only from verified domains. Read More

How to pass properties to the Log4j configuration file

Publish Date: Aug 4, 2025
Task

GOAL

You want to use dynamic values in your log4j xml configuration file. For example, you have a File Appender, and the path to that log file depends on the environment the app is deployed.
Steps
The configuration for the appender will look something like this:
<Configuration>
...
<Appenders>
        <RollingFile name="file" fileName="/Users/rneira/Documents/${sys:pathLogFile}-log4j-override.log" 
                 filePattern="/Users/rneira/Documents/${sys:pathLogFile}-log4j-override-%i.log">
            <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
            <SizeBasedTriggeringPolicy size="10 MB" />
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>
</Appenders>
...
</Configuration>

Now, we need to pass the environment variable. There is How can I set Mule and Java system properties at startup? that explains how to pass these additional properties.
For the above example, starting your server this way:
mule -M-DpathLogFile=dev

Will result in the file /Users/rneira/Documents/dev-log4j-override.log being generated for that runtime and appender.
Knowledge Article Number

001114739

 
Loading
Salesforce Help | Article