[logback-dev] svn commit: r1179 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic logback-classic/src/main/java/ch/qos/logback/classic/jmx logback-site/src/site/xdocTemplates

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Jan 9 14:43:00 CET 2007


Author: seb
Date: Tue Jan  9 14:43:00 2007
New Revision: 1179

Added:
   logback/trunk/logback-site/src/site/xdocTemplates/jmxConfig.xml
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java
   logback/trunk/logback-site/src/site/xdocTemplates/access.xml
   logback/trunk/logback-site/src/site/xdocTemplates/documentation.xml

Log:
JMX confgurator now allows to retrieve level and effective level information for a logger passed as a parameter.
Added a doc about the jmx Configurator 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	Tue Jan  9 14:43:00 2007
@@ -89,7 +89,7 @@
     instanceCount++;
   }
 
-  final Level getEffectiveLevel() {
+  public final Level getEffectiveLevel() {
     return Level.toLevel(effectiveLevelInt);
   }
 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	Tue Jan  9 14:43:00 2007
@@ -160,7 +160,7 @@
    * @param name
    *          the name of the logger to search for.
    */
-  Logger exists(String name) {
+  public Logger exists(String name) {
     return (Logger) loggerCache.get(name);
   }
 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/Configurator.java	Tue Jan  9 14:43:00 2007
@@ -13,6 +13,8 @@
 public class Configurator extends ContextAwareBase implements
     ConfiguratorMBean {
 
+  private static String EMPTY = "";
+  
   public Configurator(LoggerContext loggerContext) {
     this.context = loggerContext;
   }
@@ -67,4 +69,38 @@
     }
   }
 
+  public String getLoggerLevel(String loggerName) {
+    if (loggerName == null) {
+      return EMPTY;
+    }
+    
+    loggerName = loggerName.trim();
+    
+    LoggerContext lc = (LoggerContext) context;
+    Logger logger = lc.exists(loggerName);
+    if (logger != null) {
+      return logger.getLevel().toString();
+    } else {
+      return EMPTY;
+    }
+  }
+
+  public String getLoggerEffectiveLevel(String loggerName) {
+    if (loggerName == null) {
+      return EMPTY;
+    }
+    
+    loggerName = loggerName.trim();
+    
+    LoggerContext lc = (LoggerContext) context;
+    Logger logger = lc.exists(loggerName);
+    if (logger != null) {
+      return logger.getEffectiveLevel().toString();
+    } else {
+      return EMPTY;
+    }
+  }
+  
+  
+
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/jmx/ConfiguratorMBean.java	Tue Jan  9 14:43:00 2007
@@ -13,5 +13,9 @@
   public void reload(URL url) throws JoranException;
   
   public void setLoggerLevel(String loggerName, String levelStr);
+  
+  public String getLoggerLevel(String loggerName);
+  
+  public String getLoggerEffectiveLevel(String loggerName);
 
 }

Modified: logback/trunk/logback-site/src/site/xdocTemplates/access.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/access.xml	(original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/access.xml	Tue Jan  9 14:43:00 2007
@@ -313,7 +313,7 @@
 CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"</pre></div>
 
 		<p>
-			Once started with these options, Tomcat's JMX compoenents can be access
+			Once started with these options, Tomcat's JMX compoenents can be accessed
 			with JConsole by issuing the following command in a shell:
 		</p>
 <div class="source"><pre>jconsole &amp;</pre></div>

Modified: logback/trunk/logback-site/src/site/xdocTemplates/documentation.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/documentation.xml	(original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/documentation.xml	Tue Jan  9 14:43:00 2007
@@ -22,7 +22,7 @@
       <li><a href="manual/index.html"><b>The logback manual</b></a></li>
 
 			<li>
-				<a href="access.html">An introduction to access for Jetty
+				<a href="access.html">An introduction to logback-access for Jetty
 				and Tomcat</a>
 			</li>
       <li>
@@ -31,6 +31,9 @@
       <li>
       	<a href="bridge.html">How to use the log4j bridge</a>
       </li>
+      <li>
+      	<a href="jmxConfig.html">How to use the logback JMX Configurator</a>
+      </li>
 		</ul>
 		
 		<p>Source code related documentation:</p>

Added: logback/trunk/logback-site/src/site/xdocTemplates/jmxConfig.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-site/src/site/xdocTemplates/jmxConfig.xml	Tue Jan  9 14:43:00 2007
@@ -0,0 +1,180 @@
+<?xml version="1.0"?>
+<document>
+
+  <properties>
+    <author email="ceki at qos ddoott ch ">Ceki Gulcu</author>
+    <author email="sebastien at qos ddoott ch ">Sebastien Pennec</author>
+    <title>JMX Configurator</title>
+  </properties>
+  
+	<body>
+
+    <h2>JMX Configurator</h2>
+    
+		<p>
+			As of version 0.8, logback ships with a component that allows 
+			configuration via JMX. Basically, it lets you reload the current
+			configuration, load a new one, or modify logger levels.
+		</p>
+		
+		<h3>Configuring your server</h3>
+		<p>
+			The first step is to make sure that your application server will 
+			allow the JMX Configurator to publish itself. In this document,
+			we'll cover the necessary steps in Tomcat and Jetty.
+		</p>
+		
+		<h4>Configuring Tomcat</h4>
+		<p>
+			Accessing JMX components with Tomcat requires to add the following lines
+			to the <em>$TOMCAT_HOME/bin/catalina.sh</em> configuration file:
+		</p>
+		
+<div class="source"><pre>CATALINA_OPTS="-Dcom.sun.management.jmxremote"
+CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
+CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"</pre></div>
+
+		<p>
+			Once started with these options, Tomcat's JMX compoenents can be accessed
+			with JConsole by issuing the following command in a shell:
+		</p>
+<div class="source"><pre>jconsole &amp;</pre></div>
+
+		<p>
+			You might prefer to access your components via a web-based solution using MX4J. 
+			In that case, here are the required steps:
+		</p>
+		
+		<p>
+			First, <a href="http://mx4j.sourceforge.net/">download MX4J</a>. 
+			Place the <em>mx4j-impl.jar</em> file in
+			the <em>$TOMCAT_HOME/bin/</em> directory, and the <em>mx4j-tools.jar</em>
+			in the <em>$TOMCAT_HOME/common/lib/</em> directory.
+		</p>
+		
+		<p>Then, add the following lines to the
+		<em>$TOMCAT_HOME/bin/catalina.sh</em> configuration file:
+		</p>
+
+<div class="source"><pre>&lt;!-- at the beginning of the file -->
+CATALINA_OPTS="-Dcom.sun.management.jmxremote"
+CATALINA_OPTS="$CATALINA_OPTS -Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder"
+
+&lt;!-- in the "Add on extra jar files to CLASSPATH" section -->
+CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/mx4j-impl.jar</pre></div>
+
+		<p>
+			Finally, declare a new <code>Connector</code> in the
+			<em>$TOMCAT_HOME/conf/server.xml</em> file:
+		</p>
+		
+<div class="source"><pre>&lt;Connector port="8050" 
+  handler.list="mx"
+  mx.enabled="true" 
+  mx.httpHost="localhost" 
+  mx.httpPort="8082" 
+  protocol="AJP/1.3" /></pre></div>
+  
+  	<p>
+  		Once Tomcat is started, you should be ableo to reach the JMX components by
+  		pointing a browser to the following URL:
+  	</p>
+
+<div class="source"><pre>http://host_name:8082/</pre></div>
+
+		<h4>Configuring Jetty</h4>
+		
+		<p>
+			Configuring Jetty to publish JMX components requires a few modifications to the
+			<em>$JETTY_HOME/etc/jetty.xml</em> configuration file. Here are the elements that need to be
+			added:
+		</p>
+
+<div class="source"><pre>&lt;Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer"/>
+&lt;!-- initialize the Jetty MBean container -->
+&lt;Get id="Container" name="container">
+  &lt;Call name="addEventListener">
+    &lt;Arg>
+      &lt;New class="org.mortbay.management.MBeanContainer">
+        &lt;Arg>&lt;Ref id="MBeanServer"/>&lt;/Arg>
+        &lt;Set name="managementPort">8082&lt;/Set>
+        &lt;Call name="start" />
+      &lt;/New>
+    &lt;/Arg>
+  &lt;/Call>
+&lt;/Get></pre></div>
+
+		<p>
+			Once Jetty is started with this configuration, all available components can be reviewed
+			at this address:
+		</p>
+<div class="source"><pre>http://host_name:8082/</pre></div>
+
+
+		<h3>Using the JMX Configurator</h3>
+		
+		<p>
+			The next step is to declare the JMX Configurator in the logback configuration
+			file. This is done by adding a single element, as shown below:
+		</p>
+
+<div class="source"><pre>&lt;configuration>
+
+  <b>&lt;jmxConfigurator /></b>
+
+  &lt;appender name="console" class="ch.qos.logback.classic.ConsoleAppender">
+    &lt;layout class="ch.qos.logback.classic.PatternLayout">
+      &lt;Pattern>%date [%thread] %-5level %logger{25} - %msg%n&lt;/Pattern>
+    &lt;/layout>
+  &lt;/appender>
+
+  &lt;root>
+    &lt;level value="debug"/>
+    &lt;appender-ref ref="console" />
+  &lt;/root>  
+&lt;/configuration></pre></div>
+		
+		<p>
+			Once the JMX Configurator is displayed on your screen, there are
+			several operations available.
+		</p>
+		
+		<ul>
+			<p>Reload the configuration using the same file that was previously
+			used.
+			</p>
+			<p>Reload the configuration using a file whose path is passed as
+			a parameter.</p>
+			<p>
+				Reload the configuration using a file whose URL is passed as a
+				parameter.
+			</p>
+			<p>
+				Get the level of a logger
+			</p>
+			<p>
+				Get the effective level of a logger
+			</p>
+			<p>
+				Change the level setting of a specified logger.
+			</p>
+		</ul>
+		
+		<p>
+			In the last case, you must specify the name of the logger you wish to
+			alter, and its new level.
+		</p>
+		<p>
+			The level of a logger is a value that can be null, if no specific level
+			has been configured for said logger. Its effective level, on the other
+			hand, is given with respect to the parent loggers' levels. This value cannot
+			be null, since all loggers are direct or indirect children of the root
+			logger, whose level is always set. When trying to get the level or effective 
+			level of a logger, the name of the logger has to be passed as a parameter.
+			Note that trying to get the level or effective level for a nonexistent logger
+			will not return any result.
+		</p>
+		
+
+	</body>
+</document>
\ No newline at end of file



More information about the logback-dev mailing list