Search code examples
log4jmulelog4j2mulesoftmule4

Mule not honouring log4j2.component.properties or log4j2.system.properties


I've a mule application which needs to load log4j2.xml from different locations as per the environment shown below.

app1

dev --> /etc/dev/app1/log4j2.xml    
sit --> /etc/sit/app1/log4j2.xml    
.    .    .    
prod --> /etc/prod/app1/log4j2.xml

I don't want to use spring bean loading as by the time this bean is loaded, Mule would have already initiated log context for this app1 with default configuration and writes few logs to it.

Within log4j functionality, there are log4j2.system.properties and log4j2.component.properties files. When either of them is added to classpath (src/main/resources) with log4j.configurationFile property in it, it is supposed to pick up this file during application startup itself.

Reference: Log4j System Properties

log4j.configurationFile=${config.path}/app1/log4j2.xml

config.path is defined in wrapper as system property and available to app1 holding the env path ("/etc/dev" if dev or "/etc/sit" if sit etc..)

However, both of these files are not picking up by Mule and resolving to default configuration.

Can someone please assist in making any of these files pick up by Mule during application startup itself?


Solution

  • After long research, we have to update mule_artifact.json with "logConfig" key to define the location of external log4j2.xml file in server relative to mule_home path.

    The same path may not work in local but you can create "mklink" to resemble server path in local.

    I've tested successfully both.