[slf4j-dev] [Bug 132] Fail fast with multiple SLF4J implementations on the classpath

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Wed May 13 22:30:17 CEST 2009


http://bugzilla.slf4j.org/show_bug.cgi?id=132


Robert Elliot <robert at teviotia.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Attachment #58|Second patch with better    |Inlined - note, cannot use
        description|implementation              |Collections.list(Enumeration
                   |                            |e) as it is not in Java 1.3.




--- Comment #4 from Robert Elliot <robert at teviotia.co.uk>  2009-05-13 22:30:16 ---
(From update of attachment 58)
><HTML><HEAD/><BODY linkifying="false" linkified="0" linkifytime="12"><PRE>Index: src/main/java/org/slf4j/LoggerFactory.java
>===================================================================
>--- src/main/java/org/slf4j/LoggerFactory.java	(revision 1331)
>+++ src/main/java/org/slf4j/LoggerFactory.java	(working copy)
>@@ -24,8 +24,14 @@
> 
> package org.slf4j;
> 
>+import java.io.File;
>+import java.io.IOException;
>+import java.net.URL;
>+import java.util.ArrayList;
> import java.util.Arrays;
>+import java.util.Enumeration;
> import java.util.List;
>+import java.util.zip.ZipFile;
> 
> import org.slf4j.helpers.SubstituteLoggerFactory;
> import org.slf4j.helpers.Util;
>@@ -105,6 +111,25 @@
>   private final static void performInitialization() {
>     bind();
>     versionSanityCheck();
>+    onlyOneImplementationSanityCheck();
>+  }
>+
>+  private static String staticLoggerBinderPath = StaticLoggerBinder.class.getName().replace('.', File.separatorChar) + ".class";
>+  
>+  private static void onlyOneImplementationSanityCheck() {
>+    try {
>+      Enumeration paths = LoggerFactory.class.getClassLoader().getResources(staticLoggerBinderPath);
>+      List implementations = new ArrayList();
>+      while (paths.hasMoreElements()) {
>+        implementations.add(paths.nextElement());
>+      }
>+      if (implementations.size() > 1) {
>+        throw new IllegalStateException("ClassPath contains more than one SLF4J implementation: " + implementations);
>+      }
>+    } catch (IOException ioe) {
>+      Util.reportFailure("Error getting resources from path", ioe);
>+    }
>   }
> 
>   private final static void bind() {


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the slf4j-dev mailing list