Add context to server side log messages #109

Open
opened 2026-04-13 22:01:30 +02:00 by lars.winzer · 2 comments
lars.winzer commented 2026-04-13 22:01:30 +02:00 (Migrated from git.scicore.unibas.ch)

Feature Request

Summary

Expanding on #60, the log messages should contain additional context i.e. SessionId and the request id.

Required workarround

The only workarround would be to embed them in the log message itself:

log.info("Request handled [session={}, requestId={}]", sessionId, requestId);

Description

Every log message associated with working with a request would contain the SessionId and request id.

There will be no alteration for the UserId, as it would be too confusing.

10:19:31.649 INFO     ExampleHandler [d4c445aa-3ccb-49b4-849c-af887469b35b - 42] --- Assigned username 'Max Mustermann'

Normal log messages won't have the additional fields:

10:19:31.649 INFO     ServerApp Starting server at port 5123

Log4J2 supports the Mapped Diagnostic Context (short MDC) to embed values into the log message, without explicitly embedding them into the log message. These can be set by the SessionReader after reading the RawPacket.

To differentiate between the log message with and without special fields, the RoutingAppender with the PatternLayout can be used to check for the presence or absence of keys.

Checklist

  • I have described the function in detail
  • I searched docs for alternative implementations matching my needs
  • I added relevant labels
## Feature Request <!--The reccommended type is: Task--> ### Summary Expanding on #60, the log messages should contain additional context i.e. `SessionId` and the request id. ### Required workarround The only workarround would be to embed them in the log message itself: ```java log.info("Request handled [session={}, requestId={}]", sessionId, requestId); ``` ### Description Every log message associated with working with a request would contain the SessionId and request id. There will be no alteration for the UserId, as it would be too confusing. ``` 10:19:31.649 INFO ExampleHandler [d4c445aa-3ccb-49b4-849c-af887469b35b - 42] --- Assigned username 'Max Mustermann' ``` Normal log messages won't have the additional fields: ``` 10:19:31.649 INFO ServerApp Starting server at port 5123 ``` Log4J2 supports the _Mapped Diagnostic Context_ (short [MDC](https://logging.apache.org/log4j/1.x/apidocs/org/apache/log4j/MDC.html)) to embed values into the log message, without explicitly embedding them into the log message. These can be set by the SessionReader after reading the RawPacket. To differentiate between the log message with and without special fields, the RoutingAppender with the PatternLayout can be used to check for the presence or absence of keys. ### Checklist - [x] I have described the function in detail - [x] I searched docs for alternative implementations matching my needs - [x] I added relevant labels
lars.winzer commented 2026-04-13 22:01:30 +02:00 (Migrated from git.scicore.unibas.ch)

assigned to @lars.winzer

assigned to @lars.winzer
lars.winzer commented 2026-04-27 01:10:35 +02:00 (Migrated from git.scicore.unibas.ch)

Task will be moved to Milestone 6

Task will be moved to Milestone 6
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: University-of-Basel-Studentprojects/Programmierprojekt#109