Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How log4j2 uses filter to filter logs

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how log4j2 uses filter to filter logs, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Background description

As an upgraded version of log4j, the performance of log4j2 is naturally much better than that of log4j, and at the same time, its performance is better than that of logback, even in some areas, the performance of log4j2 is several orders of magnitude higher than that of logback.   

The highlights of log4j2 are mainly reflected in these methods: asynchronism, concurrency, configuration optimization, plug-in mechanism and so on. This article takes a preliminary look at Filter based on the log4j2 plug-in mechanism.

Three filtering results of Filter.Result

After log4j2 takes the logic of the filter, it returns the corresponding filter Result result to control whether and how the log is recorded. The results of the filter are:

ACCEPT: (you don't need to go to the following filter,) you need to record the current log.

NEUTRAL: whether you need to record the current log or not is decided by the subsequent filter. If the result returned by all filters is NEUTRAL, you need to log.

DENY: (you don't need to go to the following filter,) you don't need to record the current log.

Tip: this mechanism of log4j2 is the same as that of logback.

Filter provided by log4j2 (functional brief)

Tip: the following figure is based on log4j2.13.3.

Filter description: is StringMatchFilter commonly used if the formatted (that is, the final) log information contains ${specified string}, then onMatch, otherwise onMismatch is: msg.contains (this.text)? OnMatch: onMismatch; is LevelRangeFilter if ${maxLevel}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report