Wildcard pattern for RoutingAppender of Log4j2

前端 未结 4 1123
春和景丽
春和景丽 2020-12-18 05:17

I am trying to use the new RoutingAppender of Log4j2 to route the different logs based on the MDC (ThreadContext in Log4j2). What I want to do is the following:

4条回答
  •  眼角桃花
    2020-12-18 06:01

    Thanks for the link Remko, I have found a temporary solution until that feature gets improved from the guys of Log4j2. The solution is using both RoutingAppender and Filters. This is how my log4j2 config looks like (I have properties defined but I am not showing them here):

    
        
            
            
                
                
            
            
        
    
        
            
                
                    
                        
                        
                            
                            
                        
                        
                    
                
            
        
    
    
    
        
            
                
                    
                
            
            
                
                    
                
            
        
    
    

    What I do it is calling ThreadContext.put("contextId", "") or ThreadContext.put("contextId", "something") depending on what appender I want to log. I hope the wildward feature gets implemented soon, but for the meantime, this solution is enough for me.

    Thanks!

提交回复
热议问题