Wildcard pattern for RoutingAppender of Log4j2

前端 未结 4 1112
春和景丽
春和景丽 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 05:57

    I was unhappy with the solution to define the fallback route with the trick described in https://issues.apache.org/jira/browse/LOG4J2-326 and http://logging.apache.org/log4j/2.x/faq.html#separate_log_files, because this forces me to duplicate the appender configuration contained in the routes. I do not need different appender configuration for the default route, but just a proper file name for the general log.

    Given that the default property map is looked up for an property which is undefined in its context, see https://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution, I think the most straightforward way is just to define the default, e.g.

    
        any_fruit
    
    

    and in case the thread context does not have ${ctx:fruits} the "any_fruit" is taken.

提交回复
热议问题