Log4j 2
  1. Log4j 2
  2. LOG4J2-368

PatternLayout in 1.2 bridge missing constructor

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta8
    • Fix Version/s: 2.0-beta9
    • Component/s: log4j 1.2 emulation
    • Labels:
      None
    • Environment:

      Velocity 1.7 hits this

      Description

      java.lang.NoSuchMethodError: org.apache.log4j.PatternLayout.<init>(Ljava/lang/String;)V
      at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:117) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:269) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:871) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:262) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.RuntimeInstance.requireInitialization(RuntimeInstance.java:302) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1531) ~[velocity-1.7-dep.jar:1.7]
      at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:343) ~[velocity-1.7-dep.jar:1.7]

        Activity

        Hide
        Gary Gregory added a comment -

        Here is the Velocity code:

            // This tries to create a file appender for the specified file name.
            private void initAppender(String file) throws Exception
            {
                try
                {
                    // to add the appender
                    PatternLayout layout = new PatternLayout("%d - %m%n");
                    this.appender = new RollingFileAppender(layout, file, true);
        
                    // if we successfully created the file appender,
                    // configure it and set the logger to use only it
                    appender.setMaxBackupIndex(1);
                    appender.setMaximumFileSize(100000);
        
                    // don't inherit appenders from higher in the logger heirarchy
                    logger.setAdditivity(false);
                    logger.addAppender(appender);
                    log(DEBUG_ID, "Log4JLogChute initialized using file '"+file+'\'');
                }
                catch (IOException ioe)
                {
                    rsvc.getLog().error("Could not create file appender '"+file+'\'', ioe);
                    throw ExceptionUtils.createRuntimeException("Error configuring Log4JLogChute : ", ioe);
                }
            }
        
        Show
        Gary Gregory added a comment - Here is the Velocity code: // This tries to create a file appender for the specified file name. private void initAppender( String file) throws Exception { try { // to add the appender PatternLayout layout = new PatternLayout( "%d - %m%n" ); this .appender = new RollingFileAppender(layout, file, true ); // if we successfully created the file appender, // configure it and set the logger to use only it appender.setMaxBackupIndex(1); appender.setMaximumFileSize(100000); // don't inherit appenders from higher in the logger heirarchy logger.setAdditivity( false ); logger.addAppender(appender); log(DEBUG_ID, "Log4JLogChute initialized using file '" +file+'\''); } catch (IOException ioe) { rsvc.getLog().error( "Could not create file appender '" +file+'\'', ioe); throw ExceptionUtils.createRuntimeException( "Error configuring Log4JLogChute : " , ioe); } }
        Hide
        Gus Heck added a comment -

        looking at revision 1517589, it seems that Pattern Layout is really not implemented yet:

        package org.apache.log4j;
        
        import org.apache.log4j.spi.LoggingEvent;
        
        /**
         *
         */
        public class PatternLayout extends Layout {
        
            @Override
            public String format(final LoggingEvent event) {
                return "";
            }
        
            @Override
            public boolean ignoresThrowable() {
                return true;
            }
        }
        
        

        I'm wondering what the intended approach is here? I may try my hand at a patch, but haven't played with the log4j codebase before... (I've done some fixes/features for Ant a long time ago and a smattering of fixes here/there since, but nothing in logging).

        Show
        Gus Heck added a comment - looking at revision 1517589, it seems that Pattern Layout is really not implemented yet: package org.apache.log4j; import org.apache.log4j.spi.LoggingEvent; /** * */ public class PatternLayout extends Layout { @Override public String format( final LoggingEvent event) { return ""; } @Override public boolean ignoresThrowable() { return true ; } } I'm wondering what the intended approach is here? I may try my hand at a patch, but haven't played with the log4j codebase before... (I've done some fixes/features for Ant a long time ago and a smattering of fixes here/there since, but nothing in logging).
        Hide
        Gus Heck added a comment -

        Hmm, looks like Huge swaths of the 1.2 bridge are no-op implementations... I'm guessing that the 1.2 bridge is much further behind than the rest of log4j 2.0? Or am I missing something?

        Show
        Gus Heck added a comment - Hmm, looks like Huge swaths of the 1.2 bridge are no-op implementations... I'm guessing that the 1.2 bridge is much further behind than the rest of log4j 2.0? Or am I missing something?
        Hide
        Ralph Goers added a comment -

        The 1.2 bridge is meant to be the minimum amount of stuff from Log4j 1 to pass applications over to Log4j 2. Log4j 1 Layouts, Appenders and Filters will not work with Log4j 2 so there is no point in implementing them. The only reason PatternLayout exists is because Velocity has a hard-coded reference to it. I am not sure how I missed implementing the constructor since it was created for the sole purpose of making Velocity work.

        Show
        Ralph Goers added a comment - The 1.2 bridge is meant to be the minimum amount of stuff from Log4j 1 to pass applications over to Log4j 2. Log4j 1 Layouts, Appenders and Filters will not work with Log4j 2 so there is no point in implementing them. The only reason PatternLayout exists is because Velocity has a hard-coded reference to it. I am not sure how I missed implementing the constructor since it was created for the sole purpose of making Velocity work.
        Hide
        Ralph Goers added a comment -

        Fixed in revision 1517659. Please verify and close.

        Show
        Ralph Goers added a comment - Fixed in revision 1517659. Please verify and close.
        Hide
        Gus Heck added a comment -

        It allows velocity to render my template.

        Show
        Gus Heck added a comment - It allows velocity to render my template.

          People

          • Assignee:
            Ralph Goers
            Reporter:
            Gus Heck
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development