commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <>
Subject Re: [logging][PROPOSAL] a solution to incompatibility between log4j versions
Date Wed, 19 May 2004 13:53:05 GMT
With some changes to log4j HEAD and the following patch to
commons-logging, it is now possible to compile commons-logging with
1.3alpha and run it with both 1.3 *and* 1.2.8. Unfortunately, I was
unable to get a c-l version compiled with 1.2.8 to also run with 1.3. 
Mostly because I am unable to grok the java.lang.VerifyError.

      [java] No suitable Log constructor [Ljava.lang.Class;@f9f9d8 for 
      [java] java.lang.VerifyError: (class: 
org/apache/commons/logging/impl/Log4JLogger, method: warn signature: 
(Ljava/lang/Object;Ljava/lang/Throwable;)V) Incom
patible argument to function
      [java]     at java.lang.Class.getDeclaredConstructors0(Native Method)
      [java]     at 
      [java]     at java.lang.Class.getConstructor0(
      [java]     at java.lang.Class.getConstructor(
      [java]     at 
      [java]     at 
      [java]     at 
      [java]     at 
      [java]     at 
      [java]     at 
      [java]     at junit.framework.TestCase.runBare(
      [java]     at junit.framework.TestResult$1.protect(
      [java]     at 
      [java]     at
      [java]     at
      [java]     at junit.framework.TestSuite.runTest(
      [java]     at
      [java]     at junit.textui.TestRunner.doRun(
      [java]     at junit.textui.TestRunner.start(
      [java]     at junit.textui.TestRunner.main(

I would be interested if someone could explain the source of the error.

Anyway, to get 1.3 compiled code to also run on 1.2.8, the trick is to
detect if running on 1.2 and to cast a Level instance as a Priority.

The detection is straightforward:

  private static final boolean is12 = 

In Log4jLogger class, the various method calls become:

  public void debug(Object message) {
    if(is12) {
      getLogger().log(FQCN, (Priority) Level.DEBUG, message, null );
    } else {
      getLogger().log(FQCN, Level.DEBUG, message, null );

Refer to the included patch file for exact details.

Note also that the was modified to reflect
the fact that the throwable is no longer available in ThrowableInfo.

At 02:57 PM 5/19/2004, Mario Ivankovits wrote:
>Shapira, Yoav wrote:
>>It'd be easy to do conditional stuff, as Joran for example is completely
>>new in log4j 1.3, with Ant's <available> tasks and related conditionals.
>I am not sure, if the "conditional stuff" helps. If you end up not being 
>binary-compatible, i think commons-logging needs two compile-steps.
>One with log4j-1.2.8 in the classpath, and one with log4j-1.3 for the 
>Log4J13Logger and then package them together in one jar.
>If we would like to avoid this, we could also use reflection at all to 
>call those log( methods, but this might result in an performance loss.
>-- Mario

Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908  

View raw message