Author: ceki Date: Fri May 4 17:43:02 2007 New Revision: 803 Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/Util.java
Log: better error reporting when no bindign is available Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java ============================================================================== --- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java (original) +++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java Fri May 4 17:43:02 2007 @@ -47,6 +47,9 @@ static ILoggerFactory loggerFactory; + static final String NO_STATICLOGGERBINDER_URL = "http://www.slf4j.org/codes.html#StaticLoggerBinder"; + static final String NULL_LF_URL = "http://www.slf4j.org/codes.html#null_LF"; + // private constructor prevents instantiation private LoggerFactory() { } @@ -55,6 +58,14 @@ static { try { loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory(); + } catch(NoClassDefFoundError ncde) { + String msg = ncde.getMessage(); + if(msg != null && msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) { + Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); + Util.reportFailure("See "+NO_STATICLOGGERBINDER_URL+" for further details."); + + } + throw ncde; } catch (Exception e) { // we should never get here Util.reportFailure("Failed to instantiate logger [" @@ -72,7 +83,7 @@ */ public static Logger getLogger(String name) { if(loggerFactory == null) { - throw new IllegalStateException("Logging factory implementation cannot be null. See also http://www.slf4j.org/codes.html#null_LF"); + throw new IllegalStateException("Logging factory implementation cannot be null. See also "+NULL_LF_URL); } return loggerFactory.getLogger(name); } Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/Util.java ============================================================================== --- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/Util.java (original) +++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/helpers/Util.java Fri May 4 17:43:02 2007 @@ -38,4 +38,8 @@ System.err.println("Reported exception:"); t.printStackTrace(); } + + static final public void reportFailure(String msg) { + System.err.println("SLF4J: " +msg); + } } _______________________________________________ dev mailing list [email protected] http://www.slf4j.org/mailman/listinfo/dev
