Change console registration speed

I am trying to integrate speed with the existing log4j.xml configuration and click on the wall. It seems I can not use the console appender - no matter what I tried, it continues to send 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> 

And the java code:

 Velocity.setProperty( "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute" ); 

Does anyone know how to do this correctly?

TIA

+8
java logging velocity
source share
3 answers

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> 

:

 <logger name="foo"> <level value="info" /> <appender-ref ref="consoleAppender" /> </logger> 

Hope this helps someone else.


EDIT # 1:

Finally, this can be done by adding the following property:

 Velocity.setProperty( "runtime.log.logsystem.log4j.logger", "root" ); 

or if .properties speed is used

 runtime.log.logsystem.log4j.logger = root 

Then I was able to change my log4j.xml file to the way I did it, it effectively changed the speed from the default logon system to default speed.log, where my root log was configured - one line ... go figure :)

+14
source share

You’ll have to dive into debugging to do this with spring.

Caution - set overrideLogging to false . This prevents spring from being an upper speed logger with 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> 
+1
source share

Are you sure your log4j.xml file is a log configuration file compiled by log4j? It is possible that another JAR in the classpath includes its own log4j configuration file.

Run the application with -Dlog4j.debug so that -Dlog4j.debug information about which file it loads the configuration from to verify that the intended file is being used.

0
source share

Source: https://habr.com/ru/post/651254/


All Articles