blob: 2277d018fdad96664d3c50fc35321b642af58fd8 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Generated by Apache Maven Doxia at 2015-05-10 -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Log4j &#x2013; JMX - Apache Log4j 2</title>
<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../css/site.css" type="text/css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/prettify.min.js"></script>
<script type="text/javascript" src="../js/site.js"></script>
<meta name="author" content="Remko Popma" />
<meta name="Date-Revision-yyyymmdd" content="20150510" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="composite">
<img class="logo-left" src="../images/ls-logo.jpg" alt="Apache logging services logo" />
<img class="logo-right" src="../images/logo.jpg" alt="Apache log4j logo" />
<div class="clear"></div>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="http://logging.apache.org/log4j/2.x/">Apache Log4j 2 &trade;</a>
<ul class="nav">
<li>
<a href="http://wiki.apache.org/logging" class="external" target="_blank" title="Logging Wiki">Logging Wiki</a>
</li>
<li>
<a href="http://www.apache.org/" class="external" target="_blank" title="Apache">Apache</a>
</li>
<li>
<a href="../../../" title="Logging Services">Logging Services</a>
</li>
<li>
<a href="https://analysis.apache.org/dashboard/index/org.apache.logging.log4j:log4j" class="external" target="_blank" title="Sonar">Sonar</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<table class="layout-table">
<tr>
<td class="sidebar">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-home"></i>Apache Log4j™ 2</li>
<li class="none">
<a href="../index.html" title="About">About</a>
</li>
<li class="none">
<a href="../download.html" title="Download">Download</a>
</li>
<li class="none">
<a href="../maven-artifacts.html" title="Maven and Ivy">Maven and Ivy</a>
</li>
<li class="none">
<a href="../build.html" title="Build">Build</a>
</li>
<li class="none">
<a href="../guidelines.html" title="Guidelines">Guidelines</a>
</li>
<li class="none">
<a href="../javastyle.html" title="Style Guide">Style Guide</a>
</li>
<li class="none">
<a href="../changelog.html" title="Changelog">Changelog</a>
</li>
<li class="collapsed">
<a href="../javadoc.html" title="Javadoc">Javadoc</a>
</li>
<li class="none">
<a href="../runtime-dependencies.html" title="Runtime Dependencies">Runtime Dependencies</a>
</li>
<li class="none">
<a href="../faq.html" title="FAQ">FAQ</a>
</li>
<li class="none">
<a href="../articles.html" title="Articles">Articles</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-book"></i>Manual</li>
<li class="none">
<a href="../manual/index.html" title="Introduction">Introduction</a>
</li>
<li class="none">
<a href="../manual/architecture.html" title="Architecture">Architecture</a>
</li>
<li class="none">
<a href="../manual/migration.html" title="Log4j 1.x Migration">Log4j 1.x Migration</a>
</li>
<li class="collapsed">
<a href="../manual/api.html" title="API">API</a>
</li>
<li class="collapsed">
<a href="../manual/configuration.html" title="Configuration">Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/webapp.html" title="Web Applications and JSPs">Web Applications and JSPs</a>
</li>
<li class="collapsed">
<a href="../manual/plugins.html" title="Plugins">Plugins</a>
</li>
<li class="collapsed">
<a href="../manual/lookups.html" title="Lookups">Lookups</a>
</li>
<li class="collapsed">
<a href="../manual/appenders.html" title="Appenders">Appenders</a>
</li>
<li class="collapsed">
<a href="../manual/layouts.html" title="Layouts">Layouts</a>
</li>
<li class="collapsed">
<a href="../manual/filters.html" title="Filters">Filters</a>
</li>
<li class="collapsed">
<a href="../manual/async.html" title="Async Loggers">Async Loggers</a>
</li>
<li class="none active">
<a href="../manual/jmx.html" title="JMX">JMX</a>
</li>
<li class="none">
<a href="../manual/logsep.html" title="Logging Separation">Logging Separation</a>
</li>
<li class="collapsed">
<a href="../manual/extending.html" title="Extending Log4j">Extending Log4j</a>
</li>
<li class="collapsed">
<a href="../manual/customconfig.html" title="Extending Log4j Configuration">Extending Log4j Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/customloglevels.html" title="Custom Log Levels">Custom Log Levels</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Components</li>
<li class="none">
<a href="../log4j-api/index.html" title="API">API</a>
</li>
<li class="none">
<a href="../log4j-core/index.html" title="Implementation">Implementation</a>
</li>
<li class="none">
<a href="../log4j-jcl/index.html" title="Commons Logging Bridge">Commons Logging Bridge</a>
</li>
<li class="none">
<a href="../log4j-1.2-api/index.html" title="Log4j 1.2 API">Log4j 1.2 API</a>
</li>
<li class="none">
<a href="../log4j-slf4j-impl/index.html" title="SLF4J Binding">SLF4J Binding</a>
</li>
<li class="none">
<a href="../log4j-jul/index.html" title="JUL Adapter">JUL Adapter</a>
</li>
<li class="none">
<a href="../log4j-to-slf4j/index.html" title="Log4j 2 to SLF4J Adapter">Log4j 2 to SLF4J Adapter</a>
</li>
<li class="none">
<a href="../log4j-flume-ng/index.html" title="Apache Flume Appender">Apache Flume Appender</a>
</li>
<li class="none">
<a href="../log4j-taglib/index.html" title="Log4j Tag Library">Log4j Tag Library</a>
</li>
<li class="none">
<a href="../log4j-jmx-gui/index.html" title="Log4j JMX GUI">Log4j JMX GUI</a>
</li>
<li class="none">
<a href="../log4j-web/index.html" title="Log4j Web Application Support">Log4j Web Application Support</a>
</li>
<li class="none">
<a href="../log4j-nosql/index.html" title="Log4j NoSQL support">Log4j NoSQL support</a>
</li>
<li class="none">
<a href="../log4j-iostreams/index.html" title="Log4j IO Streams">Log4j IO Streams</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i>Project Information</li>
<li class="none">
<a href="../dependencies.html" title="Dependencies">Dependencies</a>
</li>
<li class="none">
<a href="../dependency-convergence.html" title="Dependency Convergence">Dependency Convergence</a>
</li>
<li class="none">
<a href="../dependency-management.html" title="Dependency Management">Dependency Management</a>
</li>
<li class="none">
<a href="../team-list.html" title="Project Team">Project Team</a>
</li>
<li class="none">
<a href="../mail-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li class="none">
<a href="../issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li class="none">
<a href="../license.html" title="Project License">Project License</a>
</li>
<li class="none">
<a href="../source-repository.html" title="Source Repository">Source Repository</a>
</li>
<li class="none">
<a href="../project-summary.html" title="Project Summary">Project Summary</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Project Reports</li>
<li class="none">
<a href="../changes-report.html" title="Changes Report">Changes Report</a>
</li>
<li class="none">
<a href="../jira-report.html" title="JIRA Report">JIRA Report</a>
</li>
<li class="none">
<a href="../surefire-report.html" title="Surefire Report">Surefire Report</a>
</li>
<li class="none">
<a href="../rat-report.html" title="RAT Report">RAT Report</a>
</li>
</ul>
</div>
<div id="poweredBy">
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="../images/maven-feather.png" />
</a>
</div>
</td>
<td class="content">
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<div class="section">
<h2><a name="JMX"></a>JMX</h2>
<p>
Log4j 2 has built-in support for JMX.
The StatusLogger, ContextSelector, and all LoggerContexts,
LoggerConfigs and Appenders are instrumented with MBeans and can
be remotely monitored and controlled.
</p>
<p>Also included is a simple client GUI that can be used to
monitor the StatusLogger output, as well as to remotely reconfigure
Log4j with a different configuration file, or to edit the
current configuration directly.
</p>
</div>
<div class="section">
<h2><a name="Enabling_JMX"></a>Enabling JMX</h2>
<a name="Enabling_JMX"></a>
<p>JMX support is enabled by default. When Log4j initializes,
the StatusLogger, ContextSelector, and all LoggerContexts,
LoggerConfigs and Appenders are instrumented with MBeans.
To disable JMX completely, and prevent these MBeans from being created,
specify system property <tt>log4j2.disable.jmx=true</tt> when you start
the Java VM.
</p>
<div class="section">
<h3><a name="Local_Monitoring_and_Management"></a>Local Monitoring and Management</h3>
<a name="Local"></a>
<p>To perform local monitoring you don't need to specify any system
properties. The JConsole tool that is included in the Java JDK can be
used to monitor your application. Start JConsole by typing
<tt>$JAVA_HOME/bin/jconsole</tt> in a command shell.
For more details, see Oracle's documentation on
<a class="externalLink" href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html">how to use JConsole</a>.</p>
</div>
<div class="section">
<h3><a name="Remote_Monitoring_and_Management"></a>Remote Monitoring and Management</h3>
<a name="Remote"></a>
<p>To enable monitoring and management from remote systems, set the following system property when starting the Java VM.
</p>
<p>
<tt>com.sun.management.jmxremote.port=portNum</tt>
</p>
<p>
In the property above, <tt>portNum</tt> is the port number through
which you want to enable JMX RMI connections.
</p>
<p>
For more details, see Oracle's documentation on
<a class="externalLink" href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html#gdenl">Remote
Monitoring and Management</a>.</p>
</div>
</div>
<div class="section">
<h2><a name="Log4j_Instrumented_Components"></a>Log4j Instrumented Components</h2>
<a name="Log4j_MBeans"></a>
<p>The best way to find out which methods and attributes of the various
Log4j components are accessible via JMX is to look at the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/jmx/package-summary.html">Javadoc</a> or by exploring directly in JConsole.</p>
<p>The screenshot below shows the Log4j MBeans in JConsole.</p>
<p><img src="../images/jmx-jconsole-mbeans.png" alt="JConsole screenshot of the MBeans tab" /></p>
</div>
<div class="section">
<h2><a name="Client_GUI"></a>Client GUI</h2>
<a name="ClientGUI"></a>
<p>Log4j includes a basic client GUI that can be used to
monitor the StatusLogger output and to remotely modify the Log4j
configuration. The client GUI can be run as a stand-alone application
or as a JConsole plug-in.</p>
<div class="section">
<h3><a name="Running_the_Client_GUI_as_a_JConsole_Plug-in"></a>Running the Client GUI as a JConsole Plug-in</h3>
<p>To run the Log4j JMX Client GUI as a JConsole Plug-in,
start JConsole with the following command:
</p>
<p><tt>$JAVA_HOME/bin/jconsole -pluginpath /path/to/log4j-api-2.3.jar:/path/to/log4j-core-2.3.jar:/path/to/log4j-jmx-gui-2.3.jar</tt></p>
<p>or on Windows:</p>
<p><tt>%JAVA_HOME%\bin\jconsole -pluginpath \path\to\log4j-api-2.3.jar;\path\to\log4j-core-2.3.jar;\path\to\log4j-jmx-gui-2.3.jar</tt></p>
<p>If you execute the above command and connect to your application,
you will see an extra &quot;Log4j 2&quot; tab in the JConsole window.
This tab contains the client GUI, with the StatusLogger selected.
The screenshot below shows the StatusLogger panel in JConsole.
</p>
<p><img src="../images/jmx-jconsole-statuslogger.png" alt="JConsole screenshot of the StatusLogger display" /></p>
</div>
<div class="section">
<h3><a name="Remotely_Editing_the_Log4j_Configuration"></a>Remotely Editing the Log4j Configuration</h3>
<p>The client GUI also contains a simple editor that can be used
to remotely change the Log4j configuration.
</p>
<p>
The screenshot below shows the configuration edit panel in JConsole.
</p>
<p><img src="../images/jmx-jconsole-editconfig.png" alt="JConsole screenshot of the configuration file editor" /></p>
<p>The configuration edit panel provides two ways to modify
the Log4j configuration: specifying a different configuration location
URI, or modifying the configuration XML directly in the editor panel.</p>
<p>If you specify a different configuration location URI and
click the &quot;Reconfigure from Location&quot; button, the specified file
or resource must exist and be readable by the application,
or an error will occur and the configuration will not change.
If an error occurred while processing the contents of the specified resource,
Log4j will keep its original configuration, but the editor panel
will show the contents of the file you specified. </p>
<p>
The text area showing the contents of the configuration file is
editable, and you can directly modify the configuration in this
editor panel. Clicking the &quot;Reconfigure with XML below&quot; button will
send the configuration text to the remote application where it
will be used to reconfigure Log4j on the fly.
This will not overwrite any configuration file.
Reconfiguring with text from the editor happens in memory only and
the text is not permanently stored anywhere.
</p>
</div>
<div class="section">
<h3><a name="Running_the_Client_GUI_as_a_Stand-alone_Application"></a>Running the Client GUI as a Stand-alone Application</h3>
<a name="ClientStandAlone"></a>
<p>To run the Log4j JMX Client GUI as a stand-alone application,
run the following command:
</p>
<p><tt>$JAVA_HOME/bin/java -cp /path/to/log4j-api-2.3.jar:/path/to/log4j-core-2.3.jar:/path/to/log4j-jmx-gui-2.3.jar org.apache.logging.log4j.jmx.gui.ClientGui &lt;options&gt;</tt></p>
<p>or on Windows:</p>
<p><tt>%JAVA_HOME%\bin\java -cp \path\to\log4j-api-2.3.jar;\path\to\log4j-core-2.3.jar;\path\to\log4j-jmx-gui-2.3.jar org.apache.logging.log4j.jmx.gui.ClientGui &lt;options&gt;</tt></p>
<p>Where <tt>options</tt> are one of the following:</p>
<ul>
<li><tt>&lt;host&gt;:&lt;port&gt;</tt></li>
<li><tt>service:jmx:rmi:///jndi/rmi://&lt;host&gt;:&lt;port&gt;/jmxrmi</tt></li>
<li><tt>service:jmx:rmi://&lt;host&gt;:&lt;port&gt;/jndi/rmi://&lt;host&gt;:&lt;port&gt;/jmxrmi</tt></li>
</ul>
<p>The port number must be the same as the portNum specified when
you started the application you want to monitor.
</p>
<p>For example, if you started your application with these options:</p>
<div>
<pre>com.sun.management.jmxremote.port=33445
com.sun.management.jmxremote.authenticate=false
com.sun.management.jmxremote.ssl=false</pre></div>
<p><b>(Note that this disables <i>all</i> security so this is not recommended
for production environments.
Oracle's documentation on
<a class="externalLink" href="http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html#gdenl">Remote
Monitoring and Management</a> provides details on how to configure
JMX more securely with password authentication and SSL.)</b></p>
<p>Then you can run the client with this command:</p>
<p><tt>$JAVA_HOME/bin/java -cp /path/to/log4j-api-2.3.jar:/path/to/log4j-core-2.3.jar:/path/to/log4j-jmx-gui-2.3.jar org.apache.logging.log4j.jmx.gui.ClientGui localhost:33445</tt></p>
<p>or on Windows:</p>
<p><tt>%JAVA_HOME%\bin\java -cp \path\to\log4j-api-2.3.jar;\path\to\log4j-core-2.3.jar;\path\to\log4j-jmx-gui-2.3.jar org.apache.logging.log4j.jmx.gui.ClientGui localhost:33445</tt></p>
<p>The screenshot below shows the StatusLogger panel of the client
GUI when running as a stand-alone application.</p>
<p><img src="../images/jmx-standalone-statuslogger.png" alt="JMX GUI screenshot of StatusLogger display" /></p>
<p>The screenshot below shows the configuration editor panel of the
client GUI when running as a stand-alone application.</p>
<p><img src="../images/jmx-standalone-editconfig.png" alt="JMX GUI screenshot of configuration editor" /></p>
</div>
</div>
</td>
</tr>
</table>
</div>
<div class="footer">
<p>Copyright &copy; 1999-2015 <a class="external" href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p>
<p>Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.</p>
<p>Site powered by <a class="external" href="http://getbootstrap.com/">Twitter Bootstrap</a>. Icons from <a class="external" href="http://glyphicons.com/">Glyphicons Free</a>.</p>
</div>
</div>
</body>
</html>