Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project Reactor non-blocking logging with slf4j

The log() method in Flux.class for Project Reactor mentions that if slf4j is available, it will be used. If you use a logger implementation like logback with slf4j, they are by default blocking, especially the write to file/disk part. The Reactor documents don't mention anything about this. Does anyone have thoughts/experience on this? I think one option is to maybe setup logback as async. Are there any other options? Thanks!

like image 448
kriver Avatar asked Aug 10 '18 02:08

kriver


People also ask

What logging framework does SLF4J use?

SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP. The logback project supports SLF4J natively.

Is SLF4J logger safe?

Thus, if your SLF4J provider/binding is slf4j-log4j12. jar, you are safe regarding CVE-2021-44228. If you are using log4j-over-slf4j. jar in conjunction with the SLF4J API, you are safe unless the underlying implementation is log4j 2.

What is the main benefit to using SLF4J as a logging framework?

This is the main purpose of SLF4J (Simple Logging Facade for Java) – a logging abstraction which helps to decouple your application from the underlying logger by allowing it to be plugged in – at runtime. Of course, the flexibility that such an abstraction provides is the main reason to use SLF4J.

How do I turn off Info logs in SLF4J?

To disable this behavior, you must add a logback configuration file called logback. xml in your java classpath root. You can download this minimal logback. xml file and add it in the src/main/resources directory for a maven project or beside fr directory for a simple java project.


1 Answers

I am not sure if that is an answer to your question, but by using reactor-logback I assumed that I am logging asynchronously.

I added the following log configuration (logback-spring.xml example)

<!-- Wrap calls to the logger. -->
<appender name="asyncFile" class="reactor.logback.AsyncAppender">
  <appender-ref ref="FILE"/>
</appender>

I found this information here.

like image 99
mio Avatar answered Oct 25 '22 20:10

mio