Logback Common configuration details (iii)

Source: Internet
Author: User

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</

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.