Enable/DISABLE Logging In Mule 4

 

In this tutorial we will demonstrate how can we enable/disable the logging in mule 4, logging will help to debug and monitor your application by logging the important message and the error logs, mule logs the message asynchronously which is useful to enhance the performance

Supported Log Levels:

  • DEBUG
  • ERROR
  • INFO
  • TRACE
  • WARN

 

You create a project in anypoint studio log4j.xml file automatically created which is useful to change the log level or to enable/disable the logging for any of the connector.

Default log4j.xml

<?xml version=<em>"1.0"</em> encoding=<em>"utf-8"</em>?>
<Configuration>
<!--These are some of the loggers you can enable.
There are several more you can find in the documentation.
Besides this log4j configuration, you can also use Java VM environment variables
to enable other logs like network (-Djavax.net.debug=ssl or all) and
Garbage Collector (-XX:+PrintGC). These will be append to the console, so you will
see them in the mule_ee.log file. -->
<Appenders>
<RollingFile name=<em>"file"</em> fileName=<em>"${sys:mule.home}${sys:file.separator}logs${sys:file.separator}enable-logging.log"</em>
filePattern=<em>"${sys:mule.home}${sys:file.separator}logs${sys:file.separator}enable-logging-%i.log"</em>>
<PatternLayout pattern=<em>"%-5p %d [%t] [event: %X{correlationId}] %c: %m%n"</em> />
<SizeBasedTriggeringPolicy size=<em>"10 MB"</em> />
<DefaultRolloverStrategy max=<em>"10"</em>/>
</RollingFile>
</Appenders>
<Loggers>
<!-- Http Logger shows wire traffic on DEBUG. -->
<!--AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" level="DEBUG" /-->
<AsyncLogger name=<em>"org.mule.service.http"</em> level=<em>"WARN"</em>/>
<AsyncLogger name=<em>"org.mule.extension.http"</em> level=<em>"WARN"</em>/>
<!-- Mule logger -->
<AsyncLogger name=<em>"org.mule.runtime.core.internal.processor.LoggerMessageProcessor"</em> level=<em>"INFO"</em>/>
<AsyncRoot level=<em>"INFO"</em>>
<AppenderRef ref=<em>"file"</em> />
</AsyncRoot>
</Loggers>
</Configuration>

 

Now we will see how can we enable the logging in various connector.

 

Enable HTTP Logs( HTTP Connector)

Add/uncomment the below line with level=DEBUG

<AsyncLogger name=”org.mule.service.http.impl.service.HttpMessageLogger” level=”DEBUG” />

 

Enable Salesforce Logs

Add the below line with log level as DEBUG

<AsyncLogger name=” org.mule.extension.salesforce” level=”DEBUG” />

 

Enable FTP Logs

Add the below line with log level as DEBUG

<AsyncLogger name=”org.mule.extension.ftp” level=”DEBUG” />

 

Enable Database Logs

Add the below line with log level as DEBUG

<AsyncLogger name=” org.mule.extension.db” level=”DEBUG” />

 

Enable JMS Logs

Add the below line with log level as DEBUG

<AsyncLogger name=”org.mule.extensions.jms” level=”DEBUG”/>

 

Enable VM Logs

Add the below line with log level as DEBUG

<AsyncLogger name=”org.mule.extensions.vm” level=”DEBUG”/>

 

To enable the DEBUG logs we need to provide the package name for that connector or module, if you don’t know the package name you can easily extract the same from the JAR file of the connector or module.

Now we will see how to select the package name from the jar file to add it in log4j.xml

Create a project in anypoint studio and drag and drop S3 connector

Open the JAR file for S3 connector and select the package name as org.mule.extension.s3 , you can add this package in log4j.xml to enable the logs for amazon S3, in a similar way we can add the logging for any connector

Enable Logging In Mule 4

 

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Vijay
Vijay
3 years ago

Very use full information

Saurav
Saurav
3 years ago

Very interesting and easy to understand