[slf4j-dev] [GIT] SLF4J: Simple Logging Facade for Java branch, master, updated. 7a7cf32a3e2a9e5bdc4809f5c6a4e9cc0b120ee0

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Mon Aug 24 14:36:53 CEST 2009


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  7a7cf32a3e2a9e5bdc4809f5c6a4e9cc0b120ee0 (commit)
      from  859182efbae8cb22cf8de08c4a4421657576c16f (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=7a7cf32a3e2a9e5bdc4809f5c6a4e9cc0b120ee0
http://github.com/ceki/slf4j/commit/7a7cf32a3e2a9e5bdc4809f5c6a4e9cc0b120ee0

commit 7a7cf32a3e2a9e5bdc4809f5c6a4e9cc0b120ee0
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Mon Aug 24 14:32:37 2009 +0200

    - updated javadocs.
    
     Added blurb about the performance impact of JUL to SLF4J translation.
     Other indentation changes
    
    - edited legacy.html.
    
      Usage instructions for SLF4JBridgeHandler are found in the javadocs of
      SLF4JBridgeHandler.
    
    - updated .gitignore file

diff --git a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java
new file mode 100644
index 0000000..0933696
--- /dev/null
+++ b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2004-2008 QOS.ch
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free  of charge, to any person obtaining
+ * a  copy  of this  software  and  associated  documentation files  (the
+ * "Software"), to  deal in  the Software without  restriction, including
+ * without limitation  the rights to  use, copy, modify,  merge, publish,
+ * distribute,  sublicense, and/or sell  copies of  the Software,  and to
+ * permit persons to whom the Software  is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The  above  copyright  notice  and  this permission  notice  shall  be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+ * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+ * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.slf4j.bridge;
+
+import java.util.logging.Handler;
+import java.util.logging.LogManager;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.PatternLayout;
+import org.slf4j.LoggerFactory;
+
+public class SLF4JBridgeHandlerPerfTest extends TestCase {
+
+  static String LOGGER_NAME = "yay";
+  static int RUN_LENGTH = 100*1000;
+
+  FileAppender fileAppender; 
+  org.apache.log4j.Logger log4jRoot;
+  java.util.logging.Logger julRootLogger = LogManager.getLogManager()
+  .getLogger("");
+
+  java.util.logging.Logger julLogger = java.util.logging.Logger
+      .getLogger(LOGGER_NAME);
+  org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger(LOGGER_NAME);
+  
+  Handler[] existingHandlers;
+
+  public SLF4JBridgeHandlerPerfTest(String arg0) {
+    super(arg0);
+  }
+
+  protected void setUp() throws Exception {
+    super.setUp();
+    fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log");
+
+    existingHandlers = julRootLogger.getHandlers();
+    for (int i = 0; i < existingHandlers.length; i++) {
+      julRootLogger.removeHandler(existingHandlers[i]);
+    }
+    log4jRoot = org.apache.log4j.Logger.getRootLogger();
+    log4jRoot.addAppender(fileAppender);
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    SLF4JBridgeHandler.uninstall();
+    fileAppender.close();
+    log4jRoot.getLoggerRepository().resetConfiguration();
+    for (int i = 0; i < existingHandlers.length; i++) {
+      julRootLogger.addHandler(existingHandlers[i]);
+    }
+  }
+
+  double julLoggerLoop() {
+    long start = System.nanoTime();
+    for (int i = 0; i < RUN_LENGTH; i++) {
+      julLogger.info("jul");
+    }
+    long end = System.nanoTime();
+    return (end - start) * 1.0 / RUN_LENGTH;
+  }
+
+  double slf4jLoggerLoop() {
+    long start = System.nanoTime();
+    for (int i = 0; i < RUN_LENGTH; i++) {
+      slf4jLogger.info("slf4j");
+    }
+    long end = System.nanoTime();
+    return (end - start) * 1.0 / RUN_LENGTH;
+  }
+  
+  public void testPerf() {
+    SLF4JBridgeHandler.install();
+    //log4jRoot.setLevel(org.apache.log4j.Level.ERROR);
+
+    julLoggerLoop();
+    double julAvg=julLoggerLoop();
+    System.out.println("Average cost per call (JUL->SLF4J->log4j):"+julAvg +" nanos");
+     
+    slf4jLoggerLoop();
+    double slf4jAvg=slf4jLoggerLoop();
+    System.out.println("Average cost per call (SLF4J->log4j):"+slf4jAvg +" nanos");
+    System.out.println("Ratio "+(julAvg/slf4jAvg));
+  }
+}

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

Summary of changes:
 .../slf4j/bridge/SLF4JBridgeHandlerPerfTest.java   |  109 ++++++++++++++++++++
 1 files changed, 109 insertions(+), 0 deletions(-)
 create mode 100644 jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java


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



More information about the slf4j-dev mailing list