开发者

How to Disable velocity debug and INFO log messages in my Jetty / log4j environment?

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:

  • I have a velocity properties file.
  • I have a log4j.xml file
  • I have a classpath which may error on the side of having more classes than one would expect like LogKitLogger which comes from commons-logging so it may not matter since it is not Logkit. Logkit is mentioned in the Velocity Configuring_Logging page

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:

  1. hook up velocity with log4j
  2. specify that we only want to see ERROR and above.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜