Configure logging levels on logback

logback configurations may be required if the log level, requires a combination of filters, <filter> </ fiter> label. Note that, the base is filtered by the filter in the configuration based on the root tag.

Filters can be written in the tag appender, one or more can be written, sequentially. Filters are provided for each level log enumeration value indicating handling of logs.

  DENY: Logs will not be abandoned immediately through other filters;

  NEUTRAL: an ordered list of next filter then processed through a log;

  ACCEPT: the log will be processed immediately, not through the remaining filters.

The following describes two common filter:

1, level filters

  LevelFilter:  level filter to filter a specific level logging.

<? Xml Version = "1.0" encoding = "UTF-8" ?> 
< The Configuration Debug = "false" > 
    
    <-! Console output -> 
    < appender name = "STDOUT" class = "ch.qos.logback .core.ConsoleAppender " > 
        < Encoder class =" ch.qos.logback.classic.encoder.PatternLayoutEncoder " > 
            <-! . 1 output format:% d represents the date,% thread indicates that the thread name,% - 5level: level from character width left display 5% msg: log messages,% n newline -> 
            < pattern > </ pattern > 
            < charset > UTF-. 8 </charset>
        </Encoder > 
        <-! filter out non-info log -> 
         < filter class = "ch.qos.logback.classic.filter.LevelFilter" >    
              < Level > the INFO </ Level >    
              < onMatch > ACCEPT </ onMatch >    
              < onMismatch > DENY </ onMismatch >    
          </ filter >    
    </ the appender > 
    
    
    <-! logging level order of: the TRACE <the DEBUG <the INFO <WARN <ERROR -> 
    ! <- log output level ->
    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

level: log level.

onMatch: Actions on log in line with the level of filtration. (DENY, NEUTRAL, ACCEPT)

onMismatch: Actions on log does not meet the level of filtration. (DENY, NEUTRAL, ACCEPT)

Note: the filter arranged on the basis of the level of the filter configuration, i.e. the configuration level root tag. In the present embodiment, it is greater than or equal level debug log filter, keeping only level logging info printed to the console.

2, the threshold value filter

ThresholdFilter:  threshold filter, to filter out below a specified threshold log.

It does not have too many parameters, only the default configuration. When the log level is equal to or higher than the critical value, the filter returns NEUTRAL; When the threshold level is lower than the log, log returns DENY.

<? Xml Version = "1.0" encoding = "UTF-8" ?> 
< The Configuration Debug = "false" > 
    
    <-! Console output -> 
    < appender name = "STDOUT" class = "ch.qos.logback .core.ConsoleAppender " > 
        < Encoder class =" ch.qos.logback.classic.encoder.PatternLayoutEncoder " > 
            <-! . 1 output format:% d represents the date,% thread indicates that the thread name,% - 5level: level from character width left display 5% msg: log messages,% n newline -> 
            < pattern > </ pattern > 
            < charset > UTF-. 8 </charset>
        </Encoder > 
       <! - the threshold level configuration log filter -> 
        < filter class = "ch.qos.logback.classic.filter.ThresholdFilter" > <! - only print DEBUG Log ->  
            <! - log filter off on the basis of the configuration level below the level of logging info -> 
            < level > the iNFO </ level >  
        </ filter >  
    </ the appender >   
    </ the appender > 
    
    
    <-! logging level order of: TRACE <DEBUG <iNFO < WARN <ERROR -> 
    <-! log output level -> 
    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

In this example: Based on the configuration level debug, info about the log filter out. Finally, info and info levels greater than log printing console, info, and above and debug debug log, to the subsequent filter process. If no subsequent filter processing is not.

 

Guess you like

Origin www.cnblogs.com/whalesea/p/10950628.html