commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis Lundberg (JIRA)" <>
Subject [jira] Commented: (LOGGING-114) Silent Swallowing of NoClassDefFoundError
Date Fri, 03 Aug 2007 13:34:52 GMT


Dennis Lundberg commented on LOGGING-114:

OK, I've set up a small test project to test this. Here is the java file:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;

public class TestLogging
    public static void main(String[] args) {
        Log log = LogFactory.getLog(TestLogging.class);"commons-logging logs something");
        Logger logger = Logger.getLogger("myLog4jLogger");"log4j logs something");

Log4j is present in the classpath along with commons-logging 1.1 or 1.1.1-SNAPSHOT (I tried
both) and there is a file that tells commons-logging to use log4j.
There is also a log4j.xml file that configures a DailyRollingFileAppender and an SMTPAppender.
Neither activation.jar or mail.jar is present.

However, when I run this I get the following output on the console (with or without Diagnostic

Exception in thread "main" org.apache.commons.logging.LogConfigurationException: User-specified
log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
        at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(
        at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(
        at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(
        at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(
        at org.apache.commons.logging.LogFactory.getLog(
        at TestLogging.main(

Is that not good enough or am I missing something here?

If I comment out the SMTPAppender in the configuration file everything works and two log entries
are output to the file every time the program runs.

> Silent Swallowing of NoClassDefFoundError
> -----------------------------------------
>                 Key: LOGGING-114
>                 URL:
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: 1.1.0
>         Environment: Various OSs, in combination with log4j 1.2.14.
>            Reporter: Malcolm Cleaton
>            Priority: Minor
> Hi. I'm using commons logging with log4j; my team ship a library which uses log4j, and
some of our clients use it with commons-logging.
> If commons-logging is in its default configuration, and log4j is present but fails to
load its configuration with an unhandled exception, the results are pretty nasty:
> - commons-logging silently swallows the exception and logs with something else. If diagnostics
are turned on, the message is:
>     Could not instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' -- java.lang.reflect.InvocationTargetException:
> - future attempts to use log4j directly get a pretty unhelpful error:
>     java.lang.NoClassDefFoundError at org.apache.log4j.Logger.getLogger(
> I realise you're trying to deal with a very large number of cases in this code, but it
does seem like something better could be done here. If nothing else is possible, at least
recognising the InvocationTargetException and pulling out the target exception for the diagnostic
log would have helped with tracking this one down.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message