java 将速度记录更改为控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4738705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change velocity logging to console
提问by javamonkey79
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
.
我正在尝试将速度与现有的 log4j.xml 配置集成,但遇到了麻烦。我似乎无法让它使用控制台附加程序 - 无论我尝试过什么,它都会不断发送到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>
And the java code:
和Java代码:
Velocity.setProperty( "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute" );
Does anyone know how to make this work properly?
有谁知道如何使其正常工作?
TIA
TIA
回答by javamonkey79
I got it to work by adding the following property:
我通过添加以下属性让它工作:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "foo" );
And changing this:
并改变这一点:
<logger
name="runtime.log.logsystem.log4j.category">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
to this:
对此:
<logger
name="foo">
<level
value="info" />
<appender-ref
ref="consoleAppender" />
</logger>
Hope this helps someone else.
希望这对其他人有帮助。
EDIT #1:
编辑#1:
Finally it could be done by adding the following property:
最后可以通过添加以下属性来完成:
Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "root" );
or if velocity.properties is used
或者如果使用了velocity.properties
runtime.log.logsystem.log4j.logger = root
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 :)
然后我能够将我的 log4j.xml 文件改回我的状态,这有效地将速度从日志记录更改为默认的velocity.log 到配置我的根记录器的位置 - 一行...去图:)
回答by Vadzim
Had to dive in debug to make this work with spring.
必须深入调试才能使这项工作与 spring 一起工作。
The caveat is to set overrideLogging
to false
. That prevents spring from overriding velocity logger with org.springframework.ui.velocity.CommonsLoggingLogSystem
.
需要注意的是设置overrideLogging
为false
。这可以防止 spring 用 覆盖速度记录器org.springframework.ui.velocity.CommonsLoggingLogSystem
。
<bean id="velocity" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="overrideLogging" value="false"/>
<property name="velocityProperties">
<props>
<prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.Log4JLogChute</prop>
<prop key="runtime.log.logsystem.log4j.logger">velocity</prop>
<!--...-->
</property>
</bean>
回答by matt b
Are you sure that your log4j.xml is the logging configuration file picked up by log4j? It's possible that another JAR on the classpath is including it's own bundled log4j config file.
您确定您的 log4j.xml 是 log4j 获取的日志记录配置文件吗?类路径上的另一个 JAR 可能包含它自己的捆绑 log4j 配置文件。
Launch your application with -Dlog4j.debug
to have log4j spit out information about which file it is loading the configuration from, to verify the intended file is being used.
启动您的应用程序,-Dlog4j.debug
让 log4j 吐出有关它从哪个文件加载配置的信息,以验证正在使用预期文件。