Description
Is there any request context? In java, it was ThreadLocal until async programming...then Twitter invented Context.scala and Promise.scala so MDC in logback could be swapped.
Best with example.
Filter has MDC.put("requestId", generateUniqueReqId());
in the plain old typescript code without passing loggers around all the place(bad smell if we have to pass our logger all around) ->
class SomeBizClass {
private _logger = createLogger();
public someMethod(request: FetchPhotosRequest): FetchPhotosResponse {
_logger.info("My log here"");
return ...
}
}
In this case, the output is msg="My log here" requestId="xxxsomeReqIdxxx"
Is this possible? This was an amazing thing about logback and log4j so in GCP, AWS, you simply filtered on requestId and developers never had to remember to
- pass a logger around
- type in requestId in every single log statement(nor pass requestId around).
It made things 1. extremely efficient and 2. error-prone. (no one every made any errors forgetting to pass a logger or requestID to log it).