I am getting lots of velocity debug and INFO messages showing up in my Jetty console. I would like to turn off info and debug messages that velocity spits out.
Environment:
This is a sample message
2011-04-03 13:00:14.627:/myproject:INFO: Velocity [debug] ResourceManager : found /com/somecompany/something/somefile_ok.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
It seems like the following below needs to happen in order to turn off velocity messages that we do not want to see now. We also want to make it easy to turn velocity messages back on when we need them:
Things I read:
The Stackoverflow Spit Velocity Out To Console post looked promising. However, the more I looked at the log4j.xml and compared it with the jetty configuration, the more it seems like the messages I am seeing are coming through jetty.
I have also read the Velocity Configuring_Logging page
Before I do any more Yak Shaving on this, I wanted to make sure I am on track with the approach outlined above
By the way, we're using Spring 3.x
Thanks for any help you can offer on this. :)
As suggested, here is the log4j.xml with minor tweaks to names:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: log4j.xml,v 1.6 2011-04-07 16:39:50 consumergear Exp $ -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
DEVELOPMENT CONFIGURATION
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="WARN" />
<param name="file" value="G:/logs/somewebplatform/somewebapp-webapp_log4j.log" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %5p %c:%L - %m%n" />
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="FATAL" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n" />
</layout>
</appender>
<!-- Hide those pesky Hibernate logs. -->
<logger name="net.sf">
<level value="ERROR" />
</logger>
<!-- Hide those pesky apache commons logs. -->
<logger name="org.apache.commons">
<level value="ERROR" />
</logger>
<logger name="com.yesorganization">
<level value="WARN" />
<appender-ref ref="FILE" />
</logger>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
the velocity properties with minor name tweaks
#
# specify two resource loaders to use
#
resource.loader = file, class
#
##
## for the loader we call 'file', set the FileResourceLoader as the
## class to use, turn off caching, and use 3 directories for templates
##
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = d:/projects/somewebapp-webapp/src
file.resource.loader.cache = false
file.resource.loader.modificationCheckInterval = 0
#C:/Projectsyaya/someorg/src/core/java
##
## for the loader we call 'class', use the ClasspathResourceLoader
##
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
#
#jar.resource.loader.path = jar:file:/myjarplace/myjar.jar
#jar.resource.loader.path = jar:file:/WEB-INF/lib/someorg-something-1.116.jar
If you don't want Velocity to log anything, you can change its default logging behavior. All you have to do is to implement an interface and set a property before you call Velocity. init() .
To disable USB Debugging mode: Go to Settings and scroll to the System section (on Android 8 and above, go to Settings > System) Tap Developer Options. Tap the button to toggle developer options Off.
What strikes me is that the message you show shows [debug] in the message and is logged in Log4J format as [INFO]
My guess is that velocity is using the baked in logkit and logging to standard out which is redirected by Jetty to the log4j infrastructure.
Here you can see how Jetty can be reconfigured for redirecting stdout.
I would check the config if this is the case.
Then you should replace the velocity jar with the velocity jar without dependencies (as per velocity logging instructions) and add all other dependencies EXCEPT logkit (and pray no other library needs logkit). It will then switch to using Log4J and can be configured using category org.apache.velocity
If Logkit cannot be avoided then velocity must be told to log directly to Log4j :
VelocityEngine ve = new VelocityEngine();
ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.Log4JLogChute" );
ve.init();
I've had similar runins like this, but with JBoss, not with Jetty.
Modifying Peter's answer for spring gave me a bean def that looked like
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
velocimacro.permissions.allow.inline.local.scope
runtime.log.logsystem.class=org.apache.velocity.runtime.log.Log4JLogChute
</value>
</property>
</bean>
This worked great for me.
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