将速度记录更改为控制台 [英] change velocity logging to console
问题描述
我正在尝试将速度与现有的log4j.xml配置集成在一起,并且遇到了麻烦.我似乎无法使用控制台附加程序-不管我尝试了什么,它一直发送到velocity.log
.
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>
还有Java代码:
Velocity.setProperty( "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute" );
有人知道如何使它正常工作吗?
Does anyone know how to make this work properly?
TIA
推荐答案
我通过添加以下属性使其工作:
I got it to work by adding the following property:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "foo" );
并对此进行更改:
<logger
name="runtime.log.logsystem.log4j.category">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
对此:
<logger
name="foo">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
希望这对其他人有帮助.
Hope this helps someone else.
最后可以通过添加以下属性来完成:
Finally it could be done by adding the following property:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "root" );
或者如果使用了velocity.properties
or if velocity.properties is used
runtime.log.logsystem.log4j.logger = root
然后,我能够将我的log4j.xml文件改回我的文件格式,这有效地将了速度从日志记录更改为默认的Velocity.log到配置了我的根记录器的位置-一行...去了图:)
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 :)
这篇关于将速度记录更改为控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!