Joke Collection Website - Public benefit messages - Log4j2 filter article

Log4j2 filter article

To put it simply, the filter in log4j2 mainly filters the output of logs, and qualified logs can enter the subsequent processing through the current filter; Unqualified logs should be ignored and not handled. This is a common way to use filters. At the end of the article, the use of filters is explained in detail. Here, I mainly sum up my personal experience.

MapFilter is mainly used to filter MapMessage (a class in log4J2 framework). This filter does not handle general log information, for example, it specifically handles parameters similar to the following methods.

The analysis is almost consistent with MapFilter. To filter the tags in the log information, look at the info () method of the Logger class, as shown below:

Information marked by specific tags can be filtered, otherwise it will not pass the filtering (including not using tags).

Log information that matches the regular expression will pass through the filter, as shown in appender:

Regular expression. * testing. * means several arbitrary characters (not including several, not explained here)+space+test word+space+several arbitrary characters.

For example, the A test failed because there were no spaces after the test.