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 have 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
- 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
- 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.
<Logger name=”com.mycompany” level=”INFO”/>
is now customizable in the log4j2.xml
One final note about this. The
${sys:mule.home}
has a variable which 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
="1.0"="UTF-8"
<Configuration>
<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>
<RollingFile name="monitoring" fileName="${logDir}/mule-app-${appName}-monitoring.log"
append="true"
filePattern="${logDir}/$${date:yyyy-MM}/
mule-app-${appName}-monitoring-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n" />
<TimeBasedTriggeringPolicy />
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.apache.cxf" level="WARN"/>
<Logger name="org.apache" level="WARN"/>
<Logger name="org.springframework.beans.factory" level="WARN"/>
<Logger name="org.mule.exception.CatchMessagingExceptionStrategy" level="FATAL"/>
<Logger name="org.mule.exception.DefaultMessagingExceptionStrategy" level="FATAL"/>
<Logger name="httpclient.wire" level="INFO" />
<Logger name="org.apache.commons.httpclient" level="INFO" />
<Logger name="org.mule" level="INFO"/>
<Logger name="com.mulesoft" level="INFO"/>
<Logger name="org.jetel" level="WARN"/>
<Logger name="Tracking" level="WARN"/>
<Logger name="org.glassfish.grizzly" level="INFO"/>
<Logger name="org.asynchttpclient" level="INFO"/>
<Logger name="org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate"
level="INFO" />
<Logger name="org.mule.transformer" level="WARN" />
<Logger name="org.jetel.graph" level="WARN" />
<Logger name="org.mule.transport.service.DefaultTransportServiceDescriptor"
level="WARN" />
<Logger name="com.sforce" level="INFO" />
<Logger name="org.mule.module.launcher.DeploymentDirectoryWatcher"
level="WARN" />
<Logger name="org.mule.transformer.graph" level="WARN" />
<Logger name="com.mulesoft.module.batch" level="INFO" />
<Logger name="org.mule.transport.jms.JmsMessageUtils"
level="ERROR" />
<Logger name="org.mule.lifecycle.AbstractLifecycleManager"
level="WARN" />
<Root level="INFO">
<AppenderRef ref="diagnostic"/>
</Root>
</Loggers>
</Configuration>