Stream logging

Logging is one of the most common ways to know what is happening underneath method invocations. Reactor uses SLF4J for logging, but it does not log stream operations out-of-the-box. Instead, Reactor provides the log operator, which can be used to selectively enable logging for a particular stream. Let's modify our test case using the log operator as follows:

@Testpublic void testPublisherStub() throws Exception {  Flux<Long> fibonacciGenerator = getFibonacciGenerator().log();  StringWriter out = new StringWriter();  new PrintService().printEventNumbers(fibonacciGenerator,   new PrintWriter(out));  assertTrue(out.getBuffer().length() >0);}

The log() operator is offered in many variants. By default, the operator logs at the INFO level. ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.