How can I configure Logback to log different levels for a logger to different destinations?

前端 未结 12 1818
挽巷
挽巷 2020-11-28 18:37

How can I configure Logback to log different levels for a logger to different destinations?

For example, given the following Logback configuration, will Logback reco

12条回答
  •  天涯浪人
    2020-11-28 19:03

    I take no credit for this answer, as it's merely a combination of the best two answers above: that of X. Wo Satuk and that of Sébastien Helbert: ThresholdFilter is lovely but you can't configure it to have an upper level as well as a lower level*, but combining it with two LevelFilters set to "DENY" WARN and ERROR works a treat.

    Very important: do not forget the System.err tag in the STDERR appender: my omission of it had me frustrated for a few minutes.

    
        
        
            
                INFO
            
            
                WARN
                DENY
            
            
                ERROR
                DENY
            
            
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\)
                    - %msg%n
                
            
        
    
        
            
                WARN
            
            System.err
            
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\)
                    - %msg%n
                
            
        
    
        
            
            
        
    
    

    * it does however have a method decide in the API but I haven't a clue how you'd use it in this context.

提交回复
热议问题