I am trying to setup a log4j2 xml config and am not getting the results I desire. I want my console to get level info and above, and the rolling file appender (standard) to get level debug and above. I then want to restrict 3 classes in the console appender to only receive warn and above. However, when I add these logger entries my standard appender also stops receiving the info and debug levels for these 3 classes. What should I do to only restrict console and not standard?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="threshold" value="info" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c [%t] %X{ctx} ~ %m%n" />
</layout>
</appender>
<appender name="standard" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="logs/broadcast.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{DATE} %-5p %c{1} [%t] %X{ctx} ~ %m%n" />
</layout>
</appender>
<appender name="stderr" class="org.apache.log4j.FileAppender">
<param name="file" value="logs/broadcast.err" />
<param name="threshold" value="error" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{DATE} %-5p %c{1} [%t] %X{ctx} ~ %m%n" />
</layout>
</appender>
<appender name="jlv" class="org.apache.log4j.net.SocketAppender">
<param name="remoteHost" value="localhost"/>
<param name="port" value="4445"/>
<param name="locationInfo" value="true"/>
</appender>
<logger name="com.mydetv.broadcast.BroadcastLoop">
<level value="warn"/>
<appender-ref ref="console" />
</logger>
<logger name="com.mydetv.broadcast.BroadcastUpdate22">
<level value="warn"/>
<appender-ref ref="console" />
</logger>
<logger name="com.mydetv.broadcast.vlc.VlcRequest22">
<level value="warn"/>
<appender-ref ref="console" />
</logger>
<root>
<priority value ="debug" />
<appender-ref ref="standard" />
<appender-ref ref="stderr"/>
<appender-ref ref="console" />
<appender-ref ref="jlv"/>
</root>
</log4j:configuration>
Logger
node acts as a cap or limit. for example,<Logger name="..." level="info"><appender-ref ref="common-log" level="trace" /><Logger>
, will cap all your log entries to the common log toINFO
. To remove this, you can set the level on theLogger
node toall
or simply remove it and declare explicitly by the appender. – Ives