2. Mule Logger
– We use the Logger component to log messages such as error messages, status
notifications, or exceptions.
– We can add a logger anywhere in a flow, and you can configure it to log
anything: any string, any Mule expression, or any combination of strings and
Mule expressions.
– We can log 5 different levels of log messages in mule. They are ERROR, WARN,
INFO, DEBUG and TRACE. The default level is INFO.
5. Logger - Example
INFO 2017-06-23 11:45:12,276 [[logger1].HTTP_Listener_Configuration.worker.01]
org.mule.api.processor.LoggerMessageProcessor: This is INFO message
6. Logger - Example
ERROR 2017-06-23 11:50:04,295 [[logger1].HTTP_Listener_Configuration.worker.01]
org.mule.api.processor.LoggerMessageProcessor: This is ERROR message
7. Logger - Example
ERROR 2017-06-23 11:50:04,295 [[logger1].HTTP_Listener_Configuration.worker.01]
org.mule.api.processor.LoggerMessageProcessor: This is ERROR message
8. Logger - Example
Observe that DEBUG level logs are not logged in console. This is due to we are using default log4j2
configuration which logs messages of level greater than equal to INFO and DEBUG’s level is lesser than INFO.
12. Configuring Custom Logging
Settings
– To configure custom logging settings at server level change
$MULE_HOME/conf/log4j2.xml file.
– In Anypoint Studio, log4j2.xml appears in the src/main/resources path.
– To use custom logging settings file sepeicfy log.configFile to log-settings-
file.xml(someFileName) in mule-deploy.properties. The path to log-settings-
file.xml can be either relative to working directory or an absolute path.
13. Configuring Custom Logging
Settings
– If this deployment property isn’t set, when an application is deployed, Mule
looks for a config file following a child-first pattern, as listed below:
i. Look for a file called log4j2-test.xml in the application classpath
ii. Look for a file called log4j2.xml in the application classpath
iii. Look for a file called log4j2-test.xml in the domain classpath
iv. Look for a file called log4j2.xml in the domain classpath
v. Look for a file called log4j2-test.xml in MULE_HOME/conf
vi. Look for a file called log4j2.xml in MULE_HOME/conf
vii. Apply default configuration.