I want log information in a log file using log4j. I am able to do that but the concern is I get additional information also logged in the log file.
I log information using "log.info("...");. But in the log file I see many information regarding the dispatcher start,controller called. How to fix this issue...
I assume you have read a Log4J configuration manual , if you haven't please do that first.
To answer your question: you need to tell log4j what you want to have logged and what not. The following log4j.xml configures log4j and is just an example; it needs to be placed on your classpath.
Log4j.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="INFO" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p (%d) %t::%c: %m%n" />
</layout>
</appender>
<!-- Application Loggers -->
<logger name="your package here"><level value="info" /></logger>
<!-- 3rdparty Loggers -->
<logger name="org.springframework"><level value="info" /></logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.