'Spring Webflux and non-blocking logging with log4j2
It is well known fact we should not block in a Spring Webflux applications.
In the SpringOne conferences (2020 and 2020), as well as other conferences, several presenters emphasized the importance of having non-blocking logging as well. The argument is: the business logic inside the Webflux can be non-blocking, but if the logging made is blocking, then, it is blocking.
It is easy to test if the business logic layer is non-blocking, using tools such as Blockhound etc...
However, how to ensure the logging part is also not blocking? Any tools? Recommendations? Do you guys have any example with log4j2? As sample with the pom, the configuration, the log4j2.xml will be great.
Thank you
Solution 1:[1]
What Martin suggested is correct. Following the doc, the use of org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
will be a solution.
I am also seeing references to LMAX disruptor.
Tried a combination of both and BlockHound tested, nothing blocking.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | PatPatPat |