Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Dynamically Change Mule Application Logging Level at Runtime

DZone's Guide to

Dynamically Change Mule Application Logging Level at Runtime

Let's find out the easiest way to change the logging level from WARN to DEBUG and back to WARN again. You may be doing unneeded extra work!

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

Introduction

In many situations, we need to change the logging level from WARN to DEBUG and then change it back to WARN after a period of time. There are few ways to do so. Many inexperienced developers will change log4j2.xml file. For instance, if we want to log all the requests and responses for all HTTP Listener, we can change the log4j2.xml by adding the following lines:

<AsyncLogger name="org.mule.module.http.internal.HttpMessageLogger" level="INFO"/>
<AsyncLogger name="com.ning.http" level="INFO" />

This approach works, but it is often very changing if not impossible. To change code in the production environment should be considered a last resort. There are other ways such as command line or using web services.
However, all the above-mentioned approaches require more effort than the JMX approach, which is the simplest way in my humble opinion. This article will demonstrate how we can achieve this.

Enable JMX for Mule Runtime

To enable jmx, we will need to update wrapper.conf, which is at ${MULE_HOME}/conf/wrapper.conf. Add the following lines:

wrapper.java.additional.50=-Dcom.sun.management.jmxremote
wrapper.java.additional.50=-Dcom.sun.management.jmxremote=true
wrapper.java.additional.51=-Dcom.sun.management.jmxremote.port=1099
wrapper.java.additional.53=-Dcom.sun.management.jmxremote.access.file=%MULE_HOME%/conf/jmxremote.access
wrapper.java.additional.54=-Dcom.sun.management.jmxremote.password.file=%MULE_HOME%/conf/jmxremote.password
wrapper.java.additional.56=-Dcom.sun.management.jmxremote.authenticate=true
wrapper.java.additional.55=-Dcom.sun.management.jmxremote.ssl=false

The above configuration requires to create two files: jmxremote.access and jmxremote.password under ${MULE_HOME}/conf. The following are examples:

$cat jmxremote.access
admin readwrite
gary  readonly

$cat jmxremote.password
admin admin
gary gary

To enable ssl requires generate certificates. I will cover the topic later.

Configure jvisualvm and Change Logging Level

jvisualvm comes with Java SDK. For the details about the setup, you may refer to my blog. The most important thing is to make sure you install MBeans plugin. The following snapshot shows the details:

You can traverse to the component at org.apache.logging.log4j2, under Loggers, you can change any log4j2 bean's log level as shown in the following snapshot:

In practice, you can do a lot of more with jvisualvm to inspect the Mule runtime. I will cover more in my later articles.

Build and deploy API integrations 7x faster. Try the Cloud Elements 100% RESTful platform for 30 days free. Access your trial here.

Topics:
integration ,mule ,runtime ,tutorial ,logging ,jmx

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}