1
0

Made implementation of AvalonLogger more robust (avoiding NPEs when nulls are passed in) together with a testcase. Improved build by compiling tests for only those optional components whose dependencies are present. Submitted by Neeme Praks.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Burrell Donkin
2003-05-14 11:14:24 +00:00
parent b1f47cf55f
commit 7539845c43
3 changed files with 164 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
/*
* /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/avalon/src/java/org/apache/commons/jelly/avalon/JellyService.java,v 1.1 2003/01/22 09:19:30 jstrachan Exp
* 1.1
* 2003/01/22 09:19:30
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/AvalonLogger.java,v 1.2 2003/05/14 11:12:58 rdonkin Exp $
* $Revision: 1.2 $
* $Date: 2003/05/14 11:12:58 $
*
* ====================================================================
*
@@ -57,7 +57,6 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* JellyServiceImpl.java,v 1.1 2003/01/22 09:19:30 jstrachan Exp
*/
package org.apache.commons.logging.impl;
@@ -70,6 +69,7 @@ import org.apache.commons.logging.Log;
* logging calls to Avalon logging abstraction: the Logger interface.
*
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version $Revision: 1.2 $ $Date: 2003/05/14 11:12:58 $
*/
public class AvalonLogger implements Log {
@@ -87,6 +87,8 @@ public class AvalonLogger implements Log {
* @param logger the avalon logger implementation to delegate to
*/
public AvalonLogger(String name) {
if (defaultLogger == null)
throw new NullPointerException("default logger has to be specified if this constructor is used!");
this.logger = defaultLogger.getChildLogger(name);
}
@@ -108,56 +110,56 @@ public class AvalonLogger implements Log {
* @see org.apache.commons.logging.Log#debug(java.lang.Object, java.lang.Throwable)
*/
public void debug(Object o, Throwable t) {
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString(), t);
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#debug(java.lang.Object)
*/
public void debug(Object o) {
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString());
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o));
}
/**
* @see org.apache.commons.logging.Log#error(java.lang.Object, java.lang.Throwable)
*/
public void error(Object o, Throwable t) {
if (this.logger.isErrorEnabled()) this.logger.error(o.toString(), t);
if (this.logger.isErrorEnabled()) this.logger.error(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#error(java.lang.Object)
*/
public void error(Object o) {
if (this.logger.isErrorEnabled()) this.logger.error(o.toString());
if (this.logger.isErrorEnabled()) this.logger.error(String.valueOf(o));
}
/**
* @see org.apache.commons.logging.Log#fatal(java.lang.Object, java.lang.Throwable)
*/
public void fatal(Object o, Throwable t) {
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(o.toString(), t);
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#fatal(java.lang.Object)
*/
public void fatal(Object o) {
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(o.toString());
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(String.valueOf(o));
}
/**
* @see org.apache.commons.logging.Log#info(java.lang.Object, java.lang.Throwable)
*/
public void info(Object o, Throwable t) {
if (this.logger.isInfoEnabled()) this.logger.info(o.toString(), t);
if (this.logger.isInfoEnabled()) this.logger.info(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#info(java.lang.Object)
*/
public void info(Object o) {
if (this.logger.isInfoEnabled()) this.logger.info(o.toString());
if (this.logger.isInfoEnabled()) this.logger.info(String.valueOf(o));
}
/**
@@ -206,28 +208,28 @@ public class AvalonLogger implements Log {
* @see org.apache.commons.logging.Log#trace(java.lang.Object, java.lang.Throwable)
*/
public void trace(Object o, Throwable t) {
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString(), t);
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#trace(java.lang.Object)
*/
public void trace(Object o) {
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString());
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o));
}
/**
* @see org.apache.commons.logging.Log#warn(java.lang.Object, java.lang.Throwable)
*/
public void warn(Object o, Throwable t) {
if (this.logger.isWarnEnabled()) this.logger.warn(o.toString(), t);
if (this.logger.isWarnEnabled()) this.logger.warn(String.valueOf(o), t);
}
/**
* @see org.apache.commons.logging.Log#warn(java.lang.Object)
*/
public void warn(Object o) {
if (this.logger.isWarnEnabled()) this.logger.warn(o.toString());
if (this.logger.isWarnEnabled()) this.logger.warn(String.valueOf(o));
}
}

View File

@@ -0,0 +1,96 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/avalon/AvalonLoggerTest.java,v 1.1 2003/05/14 11:14:24 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2003/05/14 11:14:24 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.logging.avalon;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.commons.logging.impl.AvalonLogger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.AbstractLogTest;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version $Revision: 1.1 $ $Date: 2003/05/14 11:14:24 $
*/
public class AvalonLoggerTest extends AbstractLogTest {
public static void main(String[] args) {
String[] testCaseName = { AvalonLoggerTest.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(AvalonLoggerTest.class);
return suite;
}
public AvalonLoggerTest(String testName) {
super(testName);
}
public Log getLogObject() {
Log log = new AvalonLogger(new ConsoleLogger());
return log;
}
}