JMX Configurator
As its name indicates, JMXConfigurator
allows
configuration of logback via JMX. In a nutshell, it lets you
reconfigure logback from the default configuration file, from a
designated file or URL, list loggers and modify logger levels.
Using the JMX Configurator
If your server run on JDK 1.6 or later, then you can just
invoke jconsole
application on the commmand line and
then connect to your server's MBeanServer. If you are running an
older JVM, then you should read the section on JMX enabling your server.
JMXConfigurator
is enabled by a single line in
your logback configuration file, as shown below:
<configuration> <jmxConfigurator /> <appender name="console" class="ch.qos.logback.classic.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%date [%thread] %-5level %logger{25} - %msg%n</Pattern> </layout> </appender> <root> <level value="debug"/> <appender-ref ref="console" /> </root> </configuration>
After you connect to your server with jconsole, on the MBeans panel, under "ch.qos.logback.classic.jmx.Configurator" folder you should see several operations to choose from, as shown in the figure below:

Thus, you can
- Reload logback configuration using the default configuration file
- Reload the configuration with the specified URL
- Reload the configuration with the specified file
- Set the level of a specified logger. To set to null, pass the string "null" as value.
- Get the level of a specified logger. Returned value can be null.
- Get the effective level of a specified logger
JMXConfigurator
exposes the list of existing
loggers and a status list as attributes.
The status list can help you diagnose logbacks internal state.

JMX enabling your server
If your server runs with JDK 1.6 or later, your server should be JMX enabled by default.
For older JVMs, we suggest that you refer JMX-related documentation of your web-server. Such documentation is available for both Tomcat and Jetty. In this document, we very briefly describe the required steps for Tomcat and Jetty.
Enabling JMX in Jetty (tested under JDK 1.5 and JDK 1.6)
The following has been tested under JDK 1.5 and 1.6. Under JDK 1.6 and later, your server is already JMX enabled by default and you can, but do not need to, follow the steps discussed below. Under JDK 1.5, adding JMX support in Jetty requires a number of additions to the $JETTY_HOME/etc/jetty.xml configuration file. Here are the elements that need to be added:
<Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer"/> <Get id="Container" name="container"> <Call name="addEventListener"> <Arg> <New class="org.mortbay.management.MBeanContainer"> <Arg><Ref id="MBeanServer"/></Arg> <Call name="start" /> </New> </Arg> </Call> </Get>
If you wish to access the MBeans exposed by Jetty with jconsole, then you need start jetty with the "com.sun.management.jmxremote" system property.
For a standalone version of Jetty, this translates to
java -Dcom.sun.management.jmxremote -jar start.jar [config files]
And if you wish to launch jetty as a Maven plugin, then you
need set the "com.sun.management.jmxremote" system property via
the MAVEN_OPTS
shell variable, as follows
MAVEN_OPTS="-Dcom.sun.management.jmxremote" mvn jetty:run
You can then access via jconsole
.

MX4J with Jetty (tested under JDK 1.5 and 1.6)
Assuming you have already downloaded MX4J, you then need to modify the jetty configuration file by adding an instruction to set the management port.
<Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer"/> <Get id="Container" name="container"> <Call name="addEventListener"> <Arg> <New class="org.mortbay.management.MBeanContainer"> <Arg><Ref id="MBeanServer"/></Arg> <Set name="managementPort">8082</Set> <Call name="start" /> </New> </Arg> </Call> </Get>
Moreover, mx4j-tools.jar needs to be added to Jetty's class path.
If you are running jetty as a Maven plug-in, then you need to add mx4j-tools as a dependency.
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <configuration> <jettyConfig>path/to/jetty.xml</jettyConfig> ... </configuration> <dependencies> <dependency> <groupId>mx4j</groupId> <artifactId>mx4j-tools</artifactId> <version>3.0.1</version> </dependency> </dependencies> </plugin>
After Jetty is started with the above configuration,
JMXConfigurator
will be available at the following
URL (search for "ch.qos.logback.classic"):
Configuring JMX for Tomcat (tested under JDK 1.5 and 1.6)
If you are using JDK 1.6 and later, your server is already JMX enabled by default and you can, but do not need to, follow the steps discussed below. Under JDK 1.5, Tomcat requires the addition of the following lines to the $TOMCAT_HOME/bin/catalina.bat/sh shell script:
CATALINA_OPTS="-Dcom.sun.management.jmxremote"
Once started with these options, Tomcat's JMX compoenents can
be accessed with jconsole
by issuing the following
command in a shell:
jconsole

MX4J with Tomcat
You might prefer to access JMX components via a web-based interface provided by MX4J. In that case, here are the required steps:
Assuming you have already downloaded MX4J, placethe mx4j-tools.jar file under the $TOMCAT_HOME/bin/ directory. Then, add the following lines to the $TOMCAT_HOME/bin/catalina.sh configuration file:
<!-- at the beginning of the file --> CATALINA_OPTS="-Dcom.sun.management.jmxremote" <!-- in the "Add on extra jar files to CLASSPATH" section --> CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/mx4j-tools.jar
Finally, declare a new Connector
in the
$TOMCAT_HOME/conf/server.xml file:
<Connector port="0" handler.list="mx" mx.enabled="true" mx.httpHost="localhost" mx.httpPort="8082" protocol="AJP/1.3" />
Once Tomcat is started, you should be able to find JMXConfigurator by pointing your browser at the following URL (search for "ch.qos.logback.classic"):