简体   繁体   中英

Log4J2: Get the current log events count available in ring buffer of asynchronous logger

We have recently moved to the Log4J 2.13 version in our Java application and are using all asynchronous logger configuration for high performance.

Under high load and logging scenarios, using asynchronous loggers has helped us a lot as the calling code executes very fast and delegating the logging request to a separate thread. However, the logging continues to happen asynchronously in the backend even after the calling code has finished - this is as per the expected results.

In the above scenario, at any point in time, we want to know how many log statements are available in the ring buffer of the asynchronous logger and are still pending to be logged. Is there a way to get this count?

Please note that we don't want the default/configured ring buffer size of the asynchronous logger in the application. Instead, we want to know its current state ie how many log statements does it hold (that are pending to be logged) at any instant in time.

Log4J provides a RingBufferAdmin MBean that exposes two operations; getBufferSize() and getRemainingCapacity(). You should be able to access that through the MBean server in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM