I'm trying to integrate velocity with an existing log4j.xml configuration and am hitting a wall. I can't seem to get it to use the console appender - no matter what I've tried it keeps sending out to velocity.log
.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender
name="consoleAppender"
class="org.apache.log4j.ConsoleAppender">
<layout
class="org.apache.log4j.PatternLayout">
<param
name="ConversionPattern"
value="%d | %5p | %m%n" />
</layout>
</appender>
<logger
name="runtime.log.logsystem.log4j.category">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
<root>
<priority
value="info" />
<appender-ref
ref="consoleAppender" />
</root>
</log4j:configuration>
And the java code:
Velocity.setProperty( "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute" );
Does anyone know how to make this work properly?
TIA
I got it to work by adding the following property:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "foo" );
And changing this:
<logger
name="runtime.log.logsystem.log4j.category">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
to this:
<logger
name="foo">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
Hope this helps someone else.
Finally it could be done by adding the following property:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "root" );
or if velocity.properties is used
runtime.log.logsystem.log4j.logger = root
I was then able to change my log4j.xml file back to how I had it, this effectively changed velocity from logging to it's default velocity.log to where my root logger was configed - one line...go figure :)
Had to dive in debug to make this work with spring.
The caveat is to set overrideLogging
to false
. That prevents spring from overriding velocity logger with org.springframework.ui.velocity.CommonsLoggingLogSystem
.
<bean id="velocity" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="overrideLogging" value="false"/>
<property name="velocityProperties">
<props>
<prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.Log4JLogChute</prop>
<prop key="runtime.log.logsystem.log4j.logger">velocity</prop>
<!--...-->
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With