This is one I’ve seen recently in some un edited log4j2.xml files:

<RollingFile name="RollingFile"
    fileName="/usr/local/mule-enterprise-standalone-3.6.1/logs/mule-app-myapp.log”
    filePattern="/usr/local/mule-enterprise-standalone-3.6.1/logs/$${date:yyyy-MM}/mule-app-myapp-%d{yyyy-MM-dd-HH}-%i.log.gz">

What’s wrong with this?  So many things…

What happens if I move this server?  What happens if I move the app?  Especially if I have two servers on the same machine.

Use instead:

<Properties>
   <Property name="logDir">${sys:mule.home}/logs</Property>
   <Property name="appName">myapp/Property>
</Properties>
<Appenders>
    <RollingFile name="diagnostic" fileName="${logDir}/mule-app-${appName}.log"
 append="true"
 filePattern="${logDir}/$${date:yyyy-MM}/mule-app-${appName}-%d{MM-dd-yyyy}-%i.log.gz">
    <PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n" />
    <TimeBasedTriggeringPolicy />
    </RollingFile>
...

Now you a variable that you edit at the top of every log4j2.xml file that will say the app name.  You can then use a basically universal config file for all your apps

To make your logger setup complete, you also need to add the category field to every logger, the naming convention I use is:

com.mycompany.mule.myappname.flowname

  1. This gives you the ability to set the level of logging specific to your loggers in an app different from any built in Mule loggers
  2. This will log the flow name in the log file that produced a particular log line.  In the above logging config the
    %c{1}

    enables this.

  3.  <Logger name=”com.mycompany” level=”INFO”/> is now customizable in the log4j2.xml

One final note about this.  The

${sys:mule.home}

as a variable requires that mule home is set effectively on your server. Sometimes this is inconsistent on mule servers started in an inconsistent way. Use the Mule as a Service to make this enterprise-grade.

Full Example log file