Velocity
  1. Velocity
  2. VELOCITY-766

Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.4
    • Fix Version/s: 1.7, 2.x
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      java version "1.6.0_17"
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

      Description

      After upgrading a web application that uses velocity from java 5 to java 6, the web application has suddenly randomly stopped working, failing suddenly when run with the following exception:

      Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration.

      Google shows that this error has something to do with logging being broken out the box:

      http://stackoverflow.com/questions/1586133/apache-velocity-can-not-initialize

      Referring specifically to this comment in the code:

      /* If the above failed, that means either the user specified a

      • logging class that we can't find, there weren't the necessary
      • dependencies in the classpath for it, or there were the same
      • problems for the default loggers, log4j and Java1.4+.
      • Since we really don't know and we want to be sure the user knows
      • that something went wrong with the logging, let's fall back to the
      • surefire SystemLogChute. No panicking or failing to log!!
        */

      It seems despite the code's best efforts, SystemLogChute is either broken or missing, and this breaks Velocity.

      Please can you use a logging framework that isn't broken out the box (I do realise that most logging frameworks have been broken out the box for years, surely there is one that isn't completely useless, I live in hope).

        Activity

        Hide
        Nathan Bubna added a comment -

        [sarcasm]Please can we do what??? No, we like broken frameworks! It was intentional, so we need more persuasion than that before we try and fix things.[/sarcasm]

        And no, the SystemLogChute is present and works fine. The actual problem is that the ServletLogChute tries to initialize because you are running a webapp (making the needed classes available), but then throws an UnsupportedOperationException because a ServletContext is not available to it in Velocity's application attributes. And the LogManager incorrectly assumes that is user-error and throws the exception onward instead of logging and trying the next LogChute. And despite your apparent doubts about our intentions, the problem will be fixed.

        In the meantime, you can do one of two things. Either put the ServletContext in your app attributes:

        VelocityEngine engine = new VelocityEngine();
        engine.setApplicationAttribute(ServletContext.class.getName(), servletContext);
        engine.init();

        or just set the runtime.log.logsystem.class property to a different logging class (i'd recommend JdkLogChute or NullLogChute), unless you prefer commons-logging or log4j for some reason.

        Show
        Nathan Bubna added a comment - [sarcasm] Please can we do what??? No, we like broken frameworks! It was intentional, so we need more persuasion than that before we try and fix things. [/sarcasm] And no, the SystemLogChute is present and works fine. The actual problem is that the ServletLogChute tries to initialize because you are running a webapp (making the needed classes available), but then throws an UnsupportedOperationException because a ServletContext is not available to it in Velocity's application attributes. And the LogManager incorrectly assumes that is user-error and throws the exception onward instead of logging and trying the next LogChute. And despite your apparent doubts about our intentions, the problem will be fixed. In the meantime, you can do one of two things. Either put the ServletContext in your app attributes: VelocityEngine engine = new VelocityEngine(); engine.setApplicationAttribute(ServletContext.class.getName(), servletContext); engine.init(); or just set the runtime.log.logsystem.class property to a different logging class (i'd recommend JdkLogChute or NullLogChute), unless you prefer commons-logging or log4j for some reason.

          People

          • Assignee:
            Unassigned
            Reporter:
            Graham Leggett
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development