Turn off debug or log messages in log4j.xml
You can turn off the log for a class or package. e.g.:
<!-- console --><appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> <param name="threshold" value="TRACE" /> <layout class="org.apache.log4j.PatternLayout"> <param name="conversionPattern" value="%d{dd MMM yyyy HH:mm:ss} %5p %c{1} - %m%n" /> </layout></appender><!-- categories --><category name="org.apache.commons"> <priority value="OFF" /></category><category name="org.apache.catalina.loader.WebappClassLoader"> <priority value="OFF" /></category><!-- root --><root> <priority value="TRACE" /> <appender-ref ref="STDOUT" /></root>
See more in Apache log4j 1.2 - Short introduction to log4j.
We should write to the log4j config file
<logger name="packageName.Class" additivity="false"> <level value="INFO" /> <appender-ref ref="fileAppender" /></logger>
I used the full qualified name of the class in the config file, which caused to the getLogger method write to the appender file only logs from the specific class. Using the name of the class only you will get in the appender file, all the logs written from other class with the same level or above.