Thread: [Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/util CommonsLoggingLog.java,NONE,1.1
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-31 22:30:16
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29716/src/java/net/sf/asterisk/util Modified Files: ThreadPool.java Added Files: CommonsLoggingLog.java LogFactory.java NullLog.java Log.java Log Message: Removed the hard runtime dependency on commons-logging. If commons-logging is available on the classpath it will be used, otherwise logging is disabled. --- NEW FILE: CommonsLoggingLog.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; import org.apache.commons.logging.LogFactory; /** * A Log implementation that acts as a proxy to commons-logging. * * @author srt * @version $Id: CommonsLoggingLog.java,v 1.1 2005/03/31 22:29:52 srt Exp $ */ public class CommonsLoggingLog implements Log { /** * The underlying commons-logging Log object to use. */ private org.apache.commons.logging.Log log; /** * Creates a new CommonsLoggingLog obtained from commons-logging's * LogFactory for the given class. * * @param clazz the class to log for. */ public CommonsLoggingLog(Class clazz) { log = LogFactory.getLog(clazz); } public void debug(Object obj) { log.debug(obj); } public void info(Object obj) { log.info(obj); } public void warn(Object obj) { log.warn(obj); } public void warn(Object obj, Throwable ex) { log.warn(obj, ex); } public void error(Object obj) { log.error(obj); } public void error(Object obj, Throwable ex) { log.error(obj, ex); } } --- NEW FILE: LogFactory.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; /** * Facade to hide details of the underlying logging system. * * @author srt * @version $Id: LogFactory.java,v 1.1 2005/03/31 22:29:52 srt Exp $ */ public final class LogFactory { /** * Indicates if commons-logging is available on the classpath or not. If the * check has not yet performed this is <code>null</code>. */ private static Boolean commonsLoggingAvailable = null; /** * Returns an instance of Log suitable for logging from the given class. * * @param clazz the class to create the logger for. * @return the created logger. */ public static Log getLog(Class clazz) { if (commonsLoggingAvailable == null) { try { Class.forName("org.apache.commons.logging.LogFactory"); commonsLoggingAvailable = Boolean.TRUE; } catch (Exception e) { commonsLoggingAvailable = Boolean.FALSE; } } if (commonsLoggingAvailable.booleanValue()) { return new CommonsLoggingLog(clazz); } else { return new NullLog(); } } } --- NEW FILE: NullLog.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; /** * A Log implementation that does nothing. * * @author srt * @version $Id: NullLog.java,v 1.1 2005/03/31 22:29:52 srt Exp $ */ public class NullLog implements Log { /** * Creates a new NullLog. */ public NullLog() { } public void debug(Object obj) { } public void info(Object obj) { } public void warn(Object obj) { } public void warn(Object obj, Throwable ex) { } public void error(Object obj) { } public void error(Object obj, Throwable ex) { } } --- NEW FILE: Log.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.util; public interface Log { void debug(Object obj); void info(Object obj); void warn(Object obj); void warn(Object obj, Throwable ex); void error(Object obj); void error(Object obj, Throwable ex); } Index: ThreadPool.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/util/ThreadPool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ThreadPool.java 10 Mar 2005 16:01:12 -0000 1.2 +++ ThreadPool.java 31 Mar 2005 22:29:52 -0000 1.3 @@ -19,8 +19,8 @@ package net.sf.asterisk.util; import java.util.LinkedList; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import net.sf.asterisk.util.Log; +import net.sf.asterisk.util.LogFactory; public class ThreadPool { |