change velocity logging to console
Solution 1
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.
EDIT #1:
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 :)
Solution 2
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>
javamonkey79
Hi, I'm Shaun! I enjoying creating software. I started my career in enterprise integration (think: camel, activemq, java). Nowadays, I typically work on back end data systems (databases, datastores, publishing, infrastructure). I work on the data engineering team, at edmunds.com (beep beep). In my formative years I was primarily interested java, Eclipse and maven, and I also use to dink around in Python, Perl, Bash Scripts, Windows Scripts, HTML, javascript, PHP, CSS, C, ASP, VB, C#, OSGi, PDE, RCP...and the list goes on. Since 2017, I've gone back end to front end and and back again, working on service engineering teams (tomcat, spring, java) to front end teams (react, redux, bootstrap) and finally back again to where I am now on data engineering (spark, spark-sql, databricks, scala). I use to blog here and here is my gitlab account here if you want to see some of the open source stuff I've done.
Updated on June 18, 2022Comments
-
javamonkey79 about 2 years
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
-
javamonkey79 over 13 yearsYeah, it's loading it. I am getting other log4j messages in the console - just not from velocity.