diff --git a/.gitignore b/.gitignore index a728ab31..9539fb57 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -*~ +.settings +target +.classpath +.project +*~ \ No newline at end of file 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 86189449..b0651850 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 @@ -75,6 +75,19 @@ import org.slf4j.spi.LocationAwareLogger; * julLogger.fine("hello world"); // this will get redirected to SLF4J * * + *
+ * 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. 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). + *
+ * + *+ * If application performance is a concern, then use of SLF4JBridgeHandler is + * appropriate only if few j.u.l. logging statements are in play. + * * @author Christian Stein * @author Joern Huxhorn * @author Ceki Gülcü 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 index 09336967..ae7d25cd 100644 --- a/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java +++ b/jul-to-slf4j/src/test/java/org/slf4j/bridge/SLF4JBridgeHandlerPerfTest.java @@ -38,6 +38,10 @@ public class SLF4JBridgeHandlerPerfTest extends TestCase { static String LOGGER_NAME = "yay"; static int RUN_LENGTH = 100*1000; + + // set to false to test enabled logging performance + boolean disabledLogger = true; + FileAppender fileAppender; org.apache.log4j.Logger log4jRoot; java.util.logging.Logger julRootLogger = LogManager.getLogManager() @@ -95,15 +99,17 @@ public class SLF4JBridgeHandlerPerfTest extends TestCase { public void testPerf() { SLF4JBridgeHandler.install(); - //log4jRoot.setLevel(org.apache.log4j.Level.ERROR); - + + if(disabledLogger) { + log4jRoot.setLevel(org.apache.log4j.Level.ERROR); + } julLoggerLoop(); double julAvg=julLoggerLoop(); - System.out.println("Average cost per call (JUL->SLF4J->log4j):"+julAvg +" nanos"); + 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("Average cost per call (SLF4J->log4j): "+slf4jAvg +" nanos"); System.out.println("Ratio "+(julAvg/slf4jAvg)); } } diff --git a/slf4j-site/src/site/pages/legacy.html b/slf4j-site/src/site/pages/legacy.html index 327ab013..e729d828 100644 --- a/slf4j-site/src/site/pages/legacy.html +++ b/slf4j-site/src/site/pages/legacy.html @@ -193,14 +193,31 @@
The jul-to-slf4j module includes a jul handler, namely SLF4JBridgeHandler, that routes all incoming jul records to the - SLF4j API. See also SLF4JBridgeHandler - javadocs. Contrary to other bridging modules such as - jcl-over-slf4j and log4j-over-slf4j, which re-implement JCL and - respectively log4j, the jul-to-slf4j modules does not re-implement - the java.util.logging package because packages under the java.* - namespace cannot be replaced. + javadocs for usage instructions.
+ +Contrary to other bridging modules such as jcl-over-slf4j and + log4j-over-slf4j, which re-implement JCL and respectively log4j, + the jul-to-slf4j modules does not re-implement the + java.util.logging package because packages under the java.* + namespace cannot be replaced. Instead, translates LogRecord into + their SLF4J equivalents. Please note that translating + java.util.logging events into SLF4J incurs the cost of + constructing LogRecord + instance regardless of whether the SLF4J logger is disabled for + the given level or nor. 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). +
+ +If application performance is a concern, then use of + SLF4JBridgeHandler is appropriate only if few j.u.l. logging + statements are in play.
+