[slf4j-dev] [GIT] SLF4J: Simple Logging Facade for Java branch master updated. v_1.6.4-11-g13f05d2

Gitbot git-noreply at pixie.qos.ch
Tue May 8 15:06:21 CEST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "SLF4J: Simple Logging Facade for Java".

The branch, master has been updated
       via  13f05d200a898247b2a8d00b0ee82461ade2004e (commit)
      from  ff5860ee622f1c49c60492e0a8a0978905f0a1d6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=slf4j.git;a=commit;h=13f05d200a898247b2a8d00b0ee82461ade2004e
http://github.com/ceki/slf4j/commit/13f05d200a898247b2a8d00b0ee82461ade2004e

commit 13f05d200a898247b2a8d00b0ee82461ade2004e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue May 8 15:05:32 2012 +0200

    added removeHandlersForRootLogger, updated javadocs

diff --git a/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java b/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java
index 783b3da..c69c9d0 100644
--- a/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java
+++ b/jul-to-slf4j/src/main/java/org/slf4j/bridge/SLF4JBridgeHandler.java
@@ -39,53 +39,61 @@ import org.slf4j.spi.LocationAwareLogger;
 // Based on http://bugzilla.slf4j.org/show_bug.cgi?id=38
 
 /**
- * Bridge/route all JUL log records to the SLF4J API.
- * 
- * <p>
- * Essentially, the idea is to install on the root logger an instance of
- * SLF4JBridgeHandler as the sole JUL handler in the system. Subsequently, the
+ * <p>Bridge/route all JUL log records to the SLF4J API.</p>
+ * <p>Essentially, the idea is to install on the root logger an instance of
+ * <code>SLF4JBridgeHandler</code> as the sole JUL handler in the system. Subsequently, the
  * SLF4JBridgeHandler instance will redirect all JUL log records are redirected
  * to the SLF4J API based on the following mapping of levels:
- * 
+ * </p>
  * <pre>
  * FINEST  -> TRACE
  * FINER   -> DEBUG
  * FINE    -> DEBUG
  * INFO    -> INFO
  * WARNING -> WARN
- * SEVER   -> ERROR
- * </pre>
- * 
- * Usage:
- * 
+ * SEVERE  -> ERROR</pre>
+ * <p><b>Programmatic installation:</b></p>
+ * <pre>
+ * // Optionally remove existing handlers attached to j.u.l root logger
+ * SLF4JBridgeHandler.removeHandlersForRootLogger();  // (since SLF4J 1.6.5)
+
+ * // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
+ * // the initialization phase of your application
+ * SLF4JBridgeHandler.install();</pre>
+ * <p><b>Installation via <em>logging.properties</em> configuration file:</b></p>
+ * <pre>
+ * // register SLF4JBridgeHandler as handler for the j.u.l. root logger
+ * handlers = org.slf4j.bridge.SLF4JBridgeHandler</pre>
+ * <p>Once SLF4JBridgeHandler is installed, logging by j.u.l. loggers will be directed to
+ * SLF4J. Example: </p>
  * <pre>
- * // call only once during initialization time of your application
- * SLF4JBridgeHandler.install();
- * 
+ * import  java.util.logging.Logger;
+ * ...
  * // usual pattern: get a Logger and then log a message
- * java.util.logging.Logger julLogger = java.util.logging.Logger
- *     .getLogger("org.wombat");
- * julLogger.fine("hello world"); // this will get redirected to SLF4J
- * </pre>
- * 
- * <p>
- * Please note that translating a java.util.logging event into SLF4J incurs the
+ * Logger julLogger = Logger.getLogger("org.wombat");
+ * julLogger.fine("hello world"); // this will get redirected to SLF4J</pre>
+ *
+ * <p>Please note that translating a java.util.logging event into SLF4J incurs the
  * cost of constructing {@link LogRecord} instance regardless of whether the
  * SLF4J logger is disabled for the given level. <b>Consequently, j.u.l. to
- * SLF4J translation can seriously impact on the cost of disabled logging
- * statements (60 fold increase) and a measurable impact on enabled log
- * statements (20% overall increase). </b>
+ * SLF4J translation can seriously increase the cost of disabled logging
+ * statements (60 fold or 6000% increase) and measurably impact the performance of enabled log
+ * statements (20% overall increase).</b> Please note that as of logback-version 0.9.25,
+ * it is possible to completely eliminate the 60 fold translation overhead for disabled
+ * log statements with the help of <a href="http://logback.qos.ch/manual/configuration.html#LevelChangePropagator">LevelChangePropagator</a>.
  * </p>
- * 
- * <p>
- * If application performance is a concern, then use of SLF4JBridgeHandler is
- * appropriate only if few j.u.l. logging statements are in play.
- * 
+ *
+ * <p>If you are concerned about application performance, then use of <code>SLF4JBridgeHandler</code>
+ * is appropriate only if any one the following two conditions is true:</p>
+ * <ol>
+ * <li>few j.u.l. logging statements are in play</li>
+ * <li>LevelChangePropagator has been installed</li>
+ * </ol>
+ *
  * @author Christian Stein
  * @author Joern Huxhorn
  * @author Ceki Gülcü
  * @author Darryl Smith
- * 
  * @since 1.5.1
  */
 public class SLF4JBridgeHandler extends Handler {
@@ -101,30 +109,32 @@ public class SLF4JBridgeHandler extends Handler {
 
   /**
    * Adds a SLF4JBridgeHandler instance to jul's root logger.
-   * 
-   * <p>
-   * This handler will redirect jul logging to SLF4J. However, only logs enabled
+   * <p/>
+   * <p/>
+   * This handler will redirect j.u.l. logging to SLF4J. However, only logs enabled
    * in j.u.l. will be redirected. For example, if a log statement invoking a
-   * j.u.l. logger disabled that statement, by definition, will <em>not</em>
-   * reach any SLF4JBridgeHandler instance and cannot be redirected.
+   * j.u.l. logger is disabled, then the corresponding non-event will <em>not</em>
+   * reach SLF4JBridgeHandler and cannot be redirected.
    */
   public static void install() {
     LogManager.getLogManager().getLogger("").addHandler(
-        new SLF4JBridgeHandler());
+            new SLF4JBridgeHandler());
+  }
+
+  private static java.util.logging.Logger getRootLogger() {
+    return LogManager.getLogManager().getLogger("");
   }
 
   /**
    * Removes previously installed SLF4JBridgeHandler instances. See also
    * {@link #install()}.
-   * 
-   * @throws SecurityException
-   *           A <code>SecurityException</code> is thrown, if a security manager
-   *           exists and if the caller does not have
-   *           LoggingPermission("control").
+   *
+   * @throws SecurityException A <code>SecurityException</code> is thrown, if a security manager
+   *                           exists and if the caller does not have
+   *                           LoggingPermission("control").
    */
   public static void uninstall() throws SecurityException {
-    java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger(
-        "");
+    java.util.logging.Logger rootLogger = getRootLogger();
     Handler[] handlers = rootLogger.getHandlers();
     for (int i = 0; i < handlers.length; i++) {
       if (handlers[i] instanceof SLF4JBridgeHandler) {
@@ -133,27 +143,38 @@ public class SLF4JBridgeHandler extends Handler {
     }
   }
 
-    /**
-     * Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
-     * @return
-     * @throws SecurityException
-     */
-    public static boolean isInstalled() throws SecurityException {
-        java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger(
-            "");
-        Handler[] handlers = rootLogger.getHandlers();
-        for (int i = 0; i < handlers.length; i++) {
-          if (handlers[i] instanceof SLF4JBridgeHandler) {
-            return true;
-          }
-        }
-        return false;
+  /**
+   * Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
+   *
+   * @return
+   * @throws SecurityException
+   */
+  public static boolean isInstalled() throws SecurityException {
+    java.util.logging.Logger rootLogger = getRootLogger();
+    Handler[] handlers = rootLogger.getHandlers();
+    for (int i = 0; i < handlers.length; i++) {
+      if (handlers[i] instanceof SLF4JBridgeHandler) {
+        return true;
       }
+    }
+    return false;
+  }
+
+  /**
+   * Invoking this method removes/unregisters/detaches all handlers currently attached to the root logger
+   * @since 1.6.5
+   */
+  public static void removeHandlersForRootLogger() {
+    java.util.logging.Logger rootLogger =  getRootLogger();
+    java.util.logging.Handler[] handlers = rootLogger.getHandlers();
+    for (int i = 0; i < handlers.length; i++) {
+      rootLogger.removeHandler(handlers[i]);
+    }
+  }
 
 
   /**
    * Initialize this handler.
-   * 
    */
   public SLF4JBridgeHandler() {
   }
@@ -184,7 +205,7 @@ public class SLF4JBridgeHandler extends Handler {
   }
 
   protected void callLocationAwareLogger(LocationAwareLogger lal,
-      LogRecord record) {
+                                         LogRecord record) {
     int julLevelValue = record.getLevel().intValue();
     int slf4jLevel;
 
@@ -219,9 +240,10 @@ public class SLF4JBridgeHandler extends Handler {
     }
   }
 
+
   /**
    * Get the record's message, possibly via a resource bundle.
-   * 
+   *
    * @param record
    * @return
    */
@@ -248,16 +270,15 @@ public class SLF4JBridgeHandler extends Handler {
 
   /**
    * Publish a LogRecord.
-   * <p>
+   * <p/>
    * The logging request was made initially to a Logger object, which
    * initialized the LogRecord and forwarded it here.
-   * <p>
+   * <p/>
    * This handler ignores the Level attached to the LogRecord, as SLF4J cares
    * about discarding log statements.
-   * 
-   * @param record
-   *          Description of the log event. A null record is silently ignored
-   *          and is not published.
+   *
+   * @param record Description of the log event. A null record is silently ignored
+   *               and is not published.
    */
   public void publish(LogRecord record) {
     // Silently ignore null records.

-----------------------------------------------------------------------

Summary of changes:
 .../java/org/slf4j/bridge/SLF4JBridgeHandler.java  |  155 +++++++++++---------
 1 files changed, 88 insertions(+), 67 deletions(-)


hooks/post-receive
-- 
SLF4J: Simple Logging Facade for Java


More information about the slf4j-dev mailing list