Last active
March 29, 2022 13:00
-
-
Save stdmitry/a0d0a6b4fe33dd40c3820c069b8fa3f1 to your computer and use it in GitHub Desktop.
Java logging example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
public class ExampleController { | |
private static final Logger log = LoggerFactory.getLogger(ExampleController.class); | |
@GetMapping("/example1") | |
public Mono<String> example1(@RequestHeader("X-Request-Id") String requestId) { | |
return | |
doSomeStuff() | |
.contextWrite(context -> context.put("requestId", requestId)) | |
; | |
} | |
private Mono<String> doSomeStuff() { | |
return | |
Mono.just("Some data") | |
.doOnEach(signal -> { | |
if (signal.isOnNext()) { | |
var requestId = (String) signal.getContextView().get("requestId"); | |
log.info("This is request id: {}", requestId); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment