Logging
Flux
can have logging by simply called log()
for example:
public Flux<User> fluxWithLogs(Flux<User> userFlux) {
return userFlux.log();
}
Which will have the following logs
[ INFO] (Test worker) | onSubscribe([Synchronous Fuseable] FluxArray.ArraySubscription)
[ INFO] (Test worker) | request(unbounded)
[ INFO] (Test worker) | onNext(reactor.learn.models.User@1187c9e8)
[ INFO] (Test worker) | onNext(reactor.learn.models.User@127a7a2e)
[ INFO] (Test worker) | onNext(reactor.learn.models.User@14008db3)
[ INFO] (Test worker) | onNext(reactor.learn.models.User@78a773fd)
[ INFO] (Test worker) | onComplete()
Custom logging
We can also do custom logging using doOn...
logs. For example:
public Flux<User> fluxWithCustomPrint(Flux<User> userFlux) {
return userFlux
.doFirst(() -> System.out.println("Starting"))
.doOnNext(user -> System.out.println(user.username))
.doOnComplete(() -> System.out.println("Completed"));
}
Which will have the following:
Starting
user1
user2
user3
user4
Completed