如何在 Jetty / log4j 环境中禁用速度调试和 INFO 日志消息?

发布于 2024-10-29 13:07:47 字数 5289 浏览 0 评论 0原文

我的 Jetty 控制台中显示了大量速度调试和信息消息。我想关闭速度吐出的信息和调试消息。

环境:

  • 我有一个速度属性文件。
  • 我有一个 log4j.xml 文件,
  • 我有一个类路径,它可能会在拥有比预期更多的类时出错,例如 LogKitLogger,它来自 commons-logging,所以这可能并不重要,因为它不是 Logkit。 VelocityConfiguration_Logging 页面中提到了 Logkit

这个是一条示例消息

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

似乎需要执行以下操作才能关闭我们现在不想看到的速度消息。我们还希望在需要时能够轻松地重新打开速度消息:

  1. 将速度与 log4j 挂钩
  2. 指定我们只想看到错误及以上错误。

我读到的内容:

我之前 我在这方面做了更多牦牛剃毛,我想确保我与上面概述的方法

顺便说一句,我们正在使用 Spring 3.x

感谢您对此提供的任何帮助。 :)

按照建议,这里是 log4j.xml,对名称进行了细微调整:

<?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>

速度属性进行了细微的名称调整

#
# 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

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆啦不做梦 2024-11-05 13:07:47

令我印象深刻的是,您显示的消息在消息中显示 [debug] 并以 Log4J 格式记录为 [INFO]

我的猜测是速度正在使用 logkit 中的烘焙并记录到标准输出,该标准输出由 Jetty 重定向到 log4j基础设施。

在这里您可以看到如何重新配置​​ Jetty 以重定向标准输出。

如果情况就是如此。

然后,您应该将velocity jar 替换为不带依赖项的velocity jar(按照velocity 日志记录说明),并添加除logkit 之外的所有其他依赖项(并祈祷没有其他库需要logkit)。然后它将切换到使用 Log4J 并可以使用类别 org.apache.velocity 进行配置

如果 Logkit 无法避免,则必须告诉 Velocity 直接登录到 Log4j :

VelocityEngine ve = new VelocityEngine();

ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
  "org.apache.velocity.runtime.log.Log4JLogChute" );

ve.init();

我也遇到过类似的情况,但使用的是 JBoss,而不是 Jetty 。

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.

寄人书 2024-11-05 13:07:47

修改 Peter 对 spring 的回答给了我一个 bean def,看起来像

<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>

这对我来说非常有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文