[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/util LogFactory.java,1.1,1.2 NullLog
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-04-20 18:22:23
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30193/src/java/net/sf/asterisk/util Modified Files: LogFactory.java Removed Files: NullLog.java CommonsLoggingLog.java Log Message: Changed logging to use either log4j, java.util.logging disable logging depending on the classes available at runtime. Index: LogFactory.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util/LogFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- LogFactory.java 31 Mar 2005 22:29:52 -0000 1.1 +++ LogFactory.java 20 Apr 2005 18:22:13 -0000 1.2 @@ -16,6 +16,10 @@ */ package net.sf.asterisk.util; +import net.sf.asterisk.util.impl.JavaLoggingLog; +import net.sf.asterisk.util.impl.Log4JLogger; +import net.sf.asterisk.util.impl.NullLog; + /** * Facade to hide details of the underlying logging system. * @@ -25,12 +29,18 @@ package net.sf.asterisk.util; public final class LogFactory { /** - * Indicates if commons-logging is available on the classpath or not. If the + * Indicates if log4j is available on the classpath or not. If the * check has not yet performed this is <code>null</code>. */ - private static Boolean commonsLoggingAvailable = null; + private static Boolean log4jLoggingAvailable = null; /** + * Indicates if java.util.logging is available on the classpath or not. If the + * check has not yet performed this is <code>null</code>. + */ + private static Boolean javaLoggingAvailable = null; + + /** * Returns an instance of Log suitable for logging from the given class. * * @param clazz the class to create the logger for. @@ -38,26 +48,44 @@ public final class LogFactory */ public static Log getLog(Class clazz) { - if (commonsLoggingAvailable == null) + if (log4jLoggingAvailable == null) { try { - Class.forName("org.apache.commons.logging.LogFactory"); - commonsLoggingAvailable = Boolean.TRUE; + Class.forName("org.apache.log4j.Logger"); + log4jLoggingAvailable = Boolean.TRUE; } catch (Exception e) { - commonsLoggingAvailable = Boolean.FALSE; + log4jLoggingAvailable = Boolean.FALSE; } } - - if (commonsLoggingAvailable.booleanValue()) + if (log4jLoggingAvailable.booleanValue()) { - return new CommonsLoggingLog(clazz); + return new Log4JLogger(clazz); } else { - return new NullLog(); + if (javaLoggingAvailable == null) + { + try + { + Class.forName("java.util.logging.Logger"); + javaLoggingAvailable = Boolean.TRUE; + } + catch (Exception e) + { + javaLoggingAvailable = Boolean.FALSE; + } + } + if (javaLoggingAvailable.booleanValue()) + { + return new JavaLoggingLog(clazz); + } + else + { + return new NullLog(); + } } } } --- NullLog.java DELETED --- --- CommonsLoggingLog.java DELETED --- |