I am using log4j for one of my projects and I know it is possible to set thresholds for each appender.
My objective is to log only INFO messages into a file and only ERROR messages in another file.
The problem of using threshold's for this is that if i set a appender threshold to INFO and the other to ERROR, when I log an ERROR message, that message goes to both files (appenders).
How can I achieve this?
Thanks in advance
We use differents logger for different levels using:
log4j.appender.XXXTracking.filter.LevelToMatch=INFO
with the option filter.LevelToMatch you could write the level that you want. This in the log4j.properties
You'll want to use org.apache.log4j.varia.LevelMatchFilter
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="ERROR" />
<param name="AcceptOnMatch" value="true" />
</filter>
Thanks for the response guys,
What i was doing wrong was that I was trying to define the filter on a properties file. Since the use of this is only suported on an XML configuration file, I have changed to an XML file.
To have exactly what I needed I also had to add a DenyAllFilter filter type:
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="INFO" />
<param name="AcceptOnMatch" value="true" />
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />
Thanks for the help guys
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.