简体   繁体   English

Apache Velocity标准日志记录配置创建太多日志输出

[英]Apache Velocity standard logging configuration creates far too much log output

I have a small web Page Project I have templated with velocity 我有一个小型网页项目,并具有速度模板化

My web.xml configuration is pretty simple 我的web.xml配置非常简单

<servlet>
  <servlet-name>velocity</servlet-name>
  <servlet-class>org.apache.velocity.tools.view.VelocityViewServlet</servlet-class>
</servlet>
<init-param>
  <param-name>org.apache.velocity.properties</param-name>
  <param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
<servlet-mapping>
  <servlet-name>velocity</servlet-name>
  <url-pattern>*.html</url-pattern>
</servlet-mapping>

My Log is full with this kind of logging from org.apache.catalina.core.ApplicationContext 我的日志充满了这种来自org.apache.catalina.core.ApplicationContext的日志记录

Nov 06, 2014 4:25:24 PM org.apache.catalina.core.ApplicationContext log
INFORMATION:  Velocity   [info] WebappResourceLoader: added template path - '/WEB-INF/velocity/'
Nov 06, 2014 4:25:24 PM org.apache.catalina.core.ApplicationContext log
INFORMATION:  Velocity  [trace] WebappResourceLoader: initialization complete.
Nov 06, 2014 4:25:24 PM org.apache.catalina.core.ApplicationContext log
INFORMATION:  Velocity  [debug] ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.StringResourceLoader

The Log entrances always look like: 'date' PM org.apache.catalina.core.ApplicationContext log INFORMATION: Velocity 'some pretty useless information'. 日志入口始终看起来像:'date'PM org.apache.catalina.core.ApplicationContext日志信息:速度“一些非常无用的信息”。

I have standard tomcat Configuration and would like to avoid changing something on tomcat level. 我有标准的tomcat配置,并希望避免在tomcat级别上进行更改。 Still don't know what to do with pretty useless 60 MB Log files per day. 仍然不知道每天要处理多少无用的60 MB日志文件。

Is there a way to reduce the amount of logs? 有没有办法减少日志量? I know the velocity documentation on logging velocity logging and I find it a little bit confusing. 我知道有关测井速度测井的速度文档,但我感到有些困惑。

Any help will be appreciated… 任何帮助将不胜感激…

The extra line is from tomcat, so you would see it with any webapp, and you won't be able to remove it without touching tomcat configuration. 额外的线从Tomcat,所以你会与任何Web应用程序看到它,你将不能够不接触Tomcat的配置将其删除。 It's not straightforward, but it's not that hard. 这并不简单,但并不难。 See for instance how to set up log4j logging (this page is for tomcat 7, but please adapt if it's not your tomcat version). 例如,请参阅如何设置log4j日志记录 (此页面适用于tomcat 7,但如果不是您的tomcat版本,请进行调整)。 In a nutshell: 简而言之:

  1. download log4j 1.2+ jar from log4j download page and put it in tomcat/lib log4j下载页面下载log4j 1.2+ jar,并将其放在tomcat/lib
  2. download tomcat-juli-adapters.jar and log4j's tomcat-juli.jar from the extras section of tomcat 7 download page . tomcat 7下载页面的Extras部分下载tomcat-juli-adapters.jar和log4j的tomcat-juli.jar tomcat-juli.jar goes in tomcat/bin and tomcat-juli-adapters.jar goes in tomcat/lib . tomcat-juli.jar放入tomcat/bintomcat-juli-adapters.jar放入tomcat/lib
  3. you must now set up a tomcat/lib/log4j.properties file. 您现在必须设置一个tomcat/lib/log4j.properties文件。 There are several examples around, here's one that logs all webapps in a daily-rotated tomcat/logs/tomcat.log file: 周围有几个示例,下面是一个将所有tomcat/logs/tomcat.log程序tomcat/logs/tomcat.log在每日旋转的tomcat/logs/tomcat.log文件中的tomcat/logs/tomcat.log

    log4j.rootCategory=info, rotating log4j.rootCategory = info,旋转
    log4j.appender.rotating=org.apache.log4j.DailyRollingFileAppender log4j.appender.rotating.File=${catalina.home}/logs/tomcat.log log4j.appender.rotating.DatePattern='.'yyyy-MM-dd log4j.appender.rotating.layout=org.apache.log4j.PatternLayout log4j.appender.rotating.layout.ConversionPattern=%d - %m%n log4j.appender.rotating = org.apache.log4j.DailyRollingFileAppender log4j.appender.rotating.File = $ {catalina.home} /logs/tomcat.log log4j.appender.rotating.DatePattern ='。'yyyy-MM-dd log4j .appender.rotating.layout = org.apache.log4j.PatternLayout log4j.appender.rotating.layout.ConversionPattern =%d-%m%n

Once you got rid of this extra line, then you can set up Velocity log level. 一旦摆脱了多余的限制,就可以设置Velocity日志级别。 Here's the relevant portion of /WEB-INF/velocity.properties : 这是/WEB-INF/velocity.properties的相关部分:

runtime.log.logsystem.class = org.apache.velocity.runtime.log.ServletLogChute
runtime.log.logsystem.servlet.level = info

The Claude Brisson Answer is probably correct if you are using log4j in your application. 如果您在应用程序中使用log4j,则Claude Brisson答案可能是正确的。 The Last part helped me the most. 最后一部分对我的帮助最大。

I am using commons-logging-1.1.jar as in the examples of the velocity project. 我在速度项目的示例中使用commons-logging-1.1.jar。 So adding just this 2 lines of configuration to /WEB-INF/velocity.properties was the solution: 因此,只需将这2行配置添加到/WEB-INF/velocity.properties就是解决方案:

runtime.log.logsystem.class = org.apache.velocity.runtime.log.ServletLogChute
runtime.log.logsystem.servlet.level = info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM