logback Common configuration details (iii) <filter>
<filter>:
filter, executing a filter will have to return an enumeration value, which is one of the deny,neutral,accept. Returns deny, the log is immediately discarded and no longer passes through the other filters; returns neutral, the next filter in the sequence table goes through the log; Returns accept, the log is processed immediately and no longer passes through the remaining filters.
Filters are added to <Appender> , and when you add one or more filters to <Appender> , you can filter the logs with any criteria. <Appender> When there are multiple filters, it is performed in the configuration order.
Here are a few common filters:
Levelfilter: level filter, filtered according to the log level. If the log level equals the configuration level, the filter receives or rejects the log based on Onmath and Onmismatch. Has the following child nodes:
<level>: Setting the filter Level
<ONMATCH>: Used to configure actions that meet the filter criteria
<ONMISMATCH>: Used to configure actions that do not meet the filter criteria
For example, the log level of the filter is configured as info, and all info-level logs are given to appender processing, not the info-level logs, and are filtered out. XML code<Configuration><AppenderName= "CONSOLE" class= "Ch.qos.logback.core.ConsoleAppender"><FilterClass= "Ch.qos.logback.classic.filter.LevelFilter">< Level>INFO</ Level> <Onmatch>ACCEPT</Onmatch><Onmismatch>DENY</Onmismatch></Filter><Encoder> <pattern>%-4relative [%thread]%-5level%logger{30}-%msg%n</pattern></Encoder></Appender><RootLevel= "DEBUG"> <Appender-refref= "CONSOLE"/></Root></Configuration>
Thresholdfilter: threshold filter that filters out logs below a specified threshold. The filter returns neutral when the log level is equal to or above the threshold value, and the log is rejected when the logging level is below the threshold.
For example: Filter out all logs below the info level. XML code<Configuration><AppenderName= "CONSOLE" class= "Ch.qos.logback.core.ConsoleAppender"><!--filter out the TRACE and DEBUG levels of logs--<FilterClass= "Ch.qos.logback.classic.filter.ThresholdFilter">< Level>INFO</ Level></Filter> <Encoder><pattern>%-4relative [%thread]%-5level%logger{30}-%msg%n</pattern></Encoder</