This is a big web server that uses Logback for logging.
I want to add an identifier for each web request (e.g., job id) and log messages with this job id according to the request that created it.
This is a multi-threaded system and the initial web request thread can be split into several other threads, but they all need to know the initial job id.
Are there any best practices for implementing this? So that I don’t have to manually pass this ID in each log message like
log.info("{} some message without parameter", jobId);
log.debug("{} another debug message with parameter {}", jobId, requiredParameter);
Ideally, it would be best to add this job id at the LayoutPattern level,
<property name="MY_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %Х{jobid} ..."/>
but how can I make the logger aware of which web request triggered it?