[logback-dev] svn commit: r1520 - in logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic: helpers joran

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu May 3 20:33:27 CEST 2007


Author: ceki
Date: Thu May  3 20:33:27 2007
New Revision: 1520

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/PlatformInfo.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java

Log:

Fixed JMX related problem observed when running under JDK 1.4.

For more details please see:

  http://marc.info/?l=logback-user&m=117766102225897&w=2


Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/PlatformInfo.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/helpers/PlatformInfo.java	Thu May  3 20:33:27 2007
@@ -0,0 +1,25 @@
+package ch.qos.logback.classic.helpers;
+
+/**
+ * This class provides information about the runtime platform.
+ *
+ * @author Ceki Gulcu
+ * */
+public class PlatformInfo {
+
+  private static final int UNINITIALIZED = -1;
+
+  private static int hasJMXObjectName = UNINITIALIZED;
+  
+  public static boolean hasJMXObjectName() {
+    if (hasJMXObjectName == UNINITIALIZED) {
+      try {
+        Class.forName("javax.management.ObjectName");
+        hasJMXObjectName = 1;
+      } catch (Throwable e) {
+        hasJMXObjectName = 0;
+      }
+    }
+    return (hasJMXObjectName == 1);
+  }
+}

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java	Thu May  3 20:33:27 2007
@@ -10,6 +10,7 @@
 
 package ch.qos.logback.classic.joran;
 
+import ch.qos.logback.classic.helpers.PlatformInfo;
 import ch.qos.logback.classic.joran.action.ConfigurationAction;
 import ch.qos.logback.classic.joran.action.ConsolePluginAction;
 import ch.qos.logback.classic.joran.action.EvaluatorAction;
@@ -59,7 +60,12 @@
         .addRule(new Pattern("configuration/appender/layout"),
             new LayoutAction());
     
-    rs.addRule(new Pattern("configuration/jmxConfigurator"), new JMXConfiguratorAction());
+    // add jmxConfigurator only if we have JMX available.
+    // If running under JDK 1.4 (retrotranslateed logback) then we
+    // might not have JMX.
+    if(PlatformInfo.hasJMXObjectName()) {
+      rs.addRule(new Pattern("configuration/jmxConfigurator"), new JMXConfiguratorAction());
+    }
     rs.addRule(new Pattern("configuration/include"), new IncludeFileAction());
     
     rs.addRule(new Pattern("configuration/consolePlugin"), new ConsolePluginAction());



More information about the logback-dev mailing list