Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.1.1
    • Labels:
      None
    • Environment:

      Commons-Logging + Log4j

      Description

      During the last few days I had major problems trying to configure Commons-Logging + Log4j on Glassfish.
      It turned out to be related to Log4j UDPAppender, but it took me needlessly long time to verify the problem was indeed in Log4j and not in Commons-Logging, Glassfish or something else. Now, why am I posting it here then - I made a small modification which logs Log4j failures more precisely, instead of just:

      [LogFactoryImpl@14810083 from org.apache.catalina.loader.WebappClassLoader@1904280] Could not instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' – java.lang.reflect.InvocationTargetException: null

      which explains, basically, nothing, you get for example:

      [LogFactoryImpl@14810083 from org.apache.catalina.loader.WebappClassLoader@1904280] Could not instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' – java.lang.reflect.InvocationTargetException: null
      [LogFactoryImpl@14810083 from org.apache.catalina.loader.WebappClassLoader@1904280] ... InvocationTargetException: java.lang.ExceptionInInitializerError: null
      [LogFactoryImpl@14810083 from org.apache.catalina.loader.WebappClassLoader@1904280] ... ExceptionInInitializerError: java.lang.IllegalStateException: Property layout must be set for UDPAppender named appenderLocalhostUdp

      which states clearly that Log4j was indeed loaded, and the problem was in its configuration.
      All it does is expand those two exceptions if they occurred. It could be more general and more elegant, but this code should work in pre-1.4 Java.

      Could you please include it in next build of Commons-Logging?

      Attaching the patch text below.

      Greetings, Lilianne E. Blaze

      Index: LogFactoryImpl.java

          • D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java Base (BASE)
          • D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java Locally Modified (Based On LOCAL)
            ***************
          • 1362,1369 ****
          • 1362,1388 ----
            + logAdapterClassName + "' – "
            + discoveryFlaw.getClass().getName() + ": "
            + discoveryFlaw.getLocalizedMessage());
            + + if ( discoveryFlaw instanceof InvocationTargetException )
            Unknown macro: {+ InvocationTargetException ite = (InvocationTargetException)discoveryFlaw;+ Throwable cause = ite.getTargetException();+ logDiagnostic("... InvocationTargetException}

            + + }
            + if (!allowFlawedDiscovery)

            { throw new LogConfigurationException(discoveryFlaw); }

      Index: Log4JLogger.java

          • D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java Base (BASE)
          • D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java Locally Modified (Based On LOCAL)
            ***************
          • 77,84 ****
          • 77,86 ----
            // ------------------------------------------------------------

      static {
      +
      if (!Priority.class.isAssignableFrom(Level.class))

      { // nope, this is log4j 1.3, so force an ExceptionInInitializerError + // note - it still works with log4j 1.3.8-alpha throw new InstantiationError("Log4J 1.2 not available"); }

      ***************

          • 112,117 ****
          • 114,124 ----
            /** For use with a log4j factory.
            */
            public Log4JLogger(Logger logger )
            Unknown macro: {+ + if( logger == null ) { + throw new IllegalArgumentException("Warning - logger == null, possible Log4j misconfiguration?"); + }+ this.name = logger.getName(); this.logger=logger; }

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          2d 5h 54m 1 Simon Kitching 20/Nov/06 07:29
          Resolved Resolved Reopened Reopened
          34s 1 Simon Kitching 20/Nov/06 07:30
          Reopened Reopened Resolved Resolved
          47s 1 Simon Kitching 20/Nov/06 07:31
          Resolved Resolved Closed Closed
          359d 15h 9m 1 Dennis Lundberg 14/Nov/07 22:40
          Dennis Lundberg made changes -
          Assignee Simon Kitching [ skitching ]
          Status Resolved [ 5 ] Closed [ 6 ]
          Dennis Lundberg made changes -
          Link This issue is duplicated by LOGGING-114 [ LOGGING-114 ]
          Simon Kitching made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Simon Kitching made changes -
          Affects Version/s 1.1.1 [ 12312160 ]
          Affects Version/s 1.1.0 [ 12311848 ]
          Hide
          Simon Kitching added a comment -

          correct "applies to" version.

          Show
          Simon Kitching added a comment - correct "applies to" version.
          Simon Kitching made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Simon Kitching made changes -
          Field Original Value New Value
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Fix Version/s 1.1.1 [ 12312160 ]
          Hide
          Simon Kitching added a comment -

          Original poster has confirmed the patch works for her.

          Show
          Simon Kitching added a comment - Original poster has confirmed the patch works for her.
          Hide
          Simon Kitching added a comment -

          Looks good to me. I've committed this patch (with a couple of extra checks for null causes).
          Thanks very much for your contribution.

          SVN commit: 476772 (LogFactoryImpl), 476774 (Log4JLogger).

          Could you please check that this works fine for you?

          Note for others: InvocationTargetException.getTargetException and ExceptionInInitializerError.getException both exist in jdk1.2.2 (supported platform for JCL).

          Show
          Simon Kitching added a comment - Looks good to me. I've committed this patch (with a couple of extra checks for null causes). Thanks very much for your contribution. SVN commit: 476772 (LogFactoryImpl), 476774 (Log4JLogger). Could you please check that this works fine for you? Note for others: InvocationTargetException.getTargetException and ExceptionInInitializerError.getException both exist in jdk1.2.2 (supported platform for JCL).
          Lilianne E. Blaze created issue -

            People

            • Assignee:
              Simon Kitching
              Reporter:
              Lilianne E. Blaze
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development