Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard pattern for RoutingAppender of Log4j2

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:

  • If MDC map has $contextId -> Append to $contextId appender (specific log)
  • If MDC does not have $contextId -> Append to main appender (general log)

I want to achieve this using a wildcard pattern in the tag and then filter using the key parameter in the for contextId (${ctx:contextId}) and using the default (without key paramenter) for the main appender, however I don't know which value is that wildcard.

Any help is appreciated, maybe I am approaching this from the wrong path. I have been reading about Filters but don't seem to work as I want.

Thanks!

like image 735
hveiga Avatar asked Aug 16 '13 18:08

hveiga


People also ask

What are filters in Log4j2?

Filters allow Log Events to be evaluated to determine if or how they should be published. A Filter will be called on one of its filter methods and will return a Result, which is an Enum that has one of 3 values - ACCEPT, DENY or NEUTRAL.

What is status in Log4j2 properties file?

Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.

What is root logger in Log4j2?

This concept is known as Logger Hierarchy. Logger Hierarchy is made up of set of LoggerConfig objects with a parent-child relationship. The topmost element in every Logger Hierarchy is the Root Logger. If Log4j2 doesn't find the configuration file, only Root Logger will be used for logging with logging level as ERROR.


1 Answers

Does this answer your question? https://issues.apache.org/jira/browse/LOG4J2-326

Remko

like image 161
Remko Popma Avatar answered Sep 28 '22 18:09

Remko Popma