1 24 25 package org.slf4j; 26 27 import org.slf4j.helpers.Util; 28 import org.slf4j.impl.StaticLoggerBinder; 29 30 46 public final class LoggerFactory { 47 48 static ILoggerFactory loggerFactory; 49 50 static final String NO_STATICLOGGERBINDER_URL = "http://www.slf4j.org/codes.html#StaticLoggerBinder"; 51 static final String NULL_LF_URL = "http://www.slf4j.org/codes.html#null_LF"; 52 53 private LoggerFactory() { 55 } 56 57 58 static { 59 try { 60 loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory(); 61 } catch(NoClassDefFoundError ncde) { 62 String msg = ncde.getMessage(); 63 if(msg != null && msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) { 64 Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); 65 Util.reportFailure("See "+NO_STATICLOGGERBINDER_URL+" for further details."); 66 67 } 68 throw ncde; 69 } catch (Exception e) { 70 Util.reportFailure("Failed to instantiate logger [" 72 + StaticLoggerBinder.SINGLETON.getLoggerFactoryClassStr() + "]", e); 73 } 74 } 75 76 84 public static Logger getLogger(String name) { 85 if(loggerFactory == null) { 86 throw new IllegalStateException ("Logging factory implementation cannot be null. See also "+NULL_LF_URL); 87 } 88 return loggerFactory.getLogger(name); 89 } 90 91 99 public static Logger getLogger(Class clazz) { 100 if(loggerFactory == null) { 101 throw new IllegalStateException ("Logging factory implementation cannot be null. See also "+NULL_LF_URL); 102 } 103 return loggerFactory.getLogger(clazz.getName()); 104 } 105 106 114 public static ILoggerFactory getILoggerFactory() { 115 return loggerFactory; 116 } 117 } 118 | Popular Tags |