Search code examples
javaspringslf4jvelocity

Configuration error with SimpleLogger (SLF4j) in Velocity


I am having some difficulty configuring some loggers for velocity in Spring. I am using Velocity 2.1, Spring 5.2.2 and SLF4J 2.0.0

org.slf4j.simple.SimpleLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.

I am trying to configure some old discarded Spring classes to build a JAR (new versions of them) to use in my application.

velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, (new SimpleLoggerFactory()).getLogger("SpringVelocityConfiguration"));

This is how I am doing it. But I keep getting the exception.

The line throwing the exception is from org.apache.velocity.runtime.RuntimeInstance:

 if (Logger.class.isAssignableFrom(o.getClass()))

From what I saw from the API documentation, SimpleLogger is a subclass to Logger. So it should work out isn't it?

Adding the dependency tree as requested:

[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ spring-velocity-support ---
[INFO] com.gtt.palabs:spring-velocity-support:jar:0.0.1-SNAPSHOT
[INFO] +- commons-logging:commons-logging:jar:1.2:provided
[INFO] +- javax.servlet:javax.servlet-api:jar:4.0.1:provided
[INFO] +- org.slf4j:slf4j-api:jar:2.0.0-alpha1:provided
[INFO] +- org.slf4j:slf4j-simple:jar:2.0.0-alpha1:compile
[INFO] +- org.springframework:spring-context:jar:5.2.2.RELEASE:provided
[INFO] |  +- org.springframework:spring-aop:jar:5.2.2.RELEASE:provided
[INFO] |  +- org.springframework:spring-beans:jar:5.2.2.RELEASE:provided
[INFO] |  \- org.springframework:spring-expression:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-core:jar:5.2.2.RELEASE:provided
[INFO] |  \- org.springframework:spring-jcl:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-web:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-webmvc:jar:5.2.2.RELEASE:provided
[INFO] +- org.apache.velocity:velocity-engine-core:jar:2.1:provided
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] +- org.apache.velocity.tools:velocity-tools-generic:jar:3.0:provided
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- org.apache.commons:commons-digester3:jar:3.2:compile
[INFO] |  |  \- cglib:cglib:jar:2.2.2:compile
[INFO] |  |     \- asm:asm:jar:3.3.1:compile
[INFO] |  \- com.github.cliftonlabs:json-simple:jar:3.0.2:provided
[INFO] \- org.apache.velocity.tools:velocity-tools-view:jar:3.0:compile

Error:

org.apache.velocity.exception.VelocityException: Error initializing log: com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:958)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:260)
    at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:90)
    at com.gtt.logicalprovisioning.velocity.utilities.VelocityBuilderSystem.<init>(VelocityBuilderSystem.java:69)
    at com.gtt.logicalprovisioning.ipflex.VelocityBuilderAction.processAction(VelocityBuilderAction.java:158)
    at com.gtt.logicalprovisioning.rtp.BaseActionListType.run(BaseActionListType.java:72)
Caused by: org.apache.velocity.exception.VelocityException: com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:931)
    ... 5 more

Solution

  • The log line says it all:

    org.apache.velocity.exception.VelocityException: Error initializing log:
    com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger
    object set as runtime.log.instance
    is not a valid org.slf4j.Logger implementation.
    

    It means that the old Spring classes you are working with do overwrite the runtime.instance.log property before Velocity initialization is carried on.