ETU-65064: Adds support for log prefix#250
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for configurable log prefixes to distinguish between incoming and outgoing HTTP calls in the logging framework. Users can now configure custom prefixes (e.g., [in] or [out]) for server and client logs separately through Spring Boot configuration properties.
- Adds a
prefixfield toMessageComposerthat allows prepending custom text to log messages - Extends
MessageFormatPropertieswith getter/setter for the prefix configuration - Updates the
MessageComposerconstructor to accept the prefix parameter
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
request-response/logbook/src/main/java/no/entur/logging/cloud/logbook/MessageComposer.java |
Adds prefix field and constructor parameter, implements prefix prepending logic in message construction |
request-response/logbook-spring-boot-autoconfigure/src/main/java/no/entur/logging/cloud/spring/logbook/properties/MessageFormatProperties.java |
Adds prefix property with getter/setter, updates toComposer() to pass prefix to MessageComposer constructor |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| protected void constructMessage(HttpRequest request, StringBuilder messageBuilder) throws IOException { | ||
| if (prefix != null) { | ||
| messageBuilder.append(prefix); |
There was a problem hiding this comment.
The prefix is appended directly without any spacing. This will result in the prefix running into the URL, producing output like GET [in]https://example.com or 200 OK [in]https://example.com. Consider adding a space after the prefix to improve readability:
if (prefix != null) {
messageBuilder.append(prefix);
messageBuilder.append(' ');
}Alternatively, document that users should include the trailing space in the prefix value itself (e.g., "[in] ").
| messageBuilder.append(prefix); | |
| messageBuilder.append(prefix); | |
| messageBuilder.append(' '); |
| protected boolean query; | ||
|
|
||
| public MessageComposer(boolean scheme, boolean host, boolean port, boolean path, boolean query) { | ||
| public MessageComposer(String prefix, boolean scheme, boolean host, boolean port, boolean path, boolean query) { |
There was a problem hiding this comment.
Adding a new parameter at the beginning of the constructor changes the constructor signature and is a breaking change for any code that directly instantiates MessageComposer. While the internal usage has been updated in MessageFormatProperties.toComposer(), external consumers who directly instantiate this class will be broken.
Consider either:
- Adding the new parameter at the end to minimize breakage:
MessageComposer(boolean scheme, boolean host, boolean port, boolean path, boolean query, String prefix) - Deprecating the old constructor and adding a new one with the prefix parameter
- If breaking changes are acceptable, document this as a breaking change in the release notes
Vi har et ønske om å kunne skille inngående med utgående kall i loggene.
Derfor trenger vi at log-konfigurasjonen støtter at man kan legge inn egendefinerte prefix for eksempel: [in] eller [out]