Skip to content

ETU-65064: Adds support for log prefix#250

Open
jonanderssol wants to merge 1 commit intoentur:mainfrom
jonanderssol:ETU-65064-supports-prefix
Open

ETU-65064: Adds support for log prefix#250
jonanderssol wants to merge 1 commit intoentur:mainfrom
jonanderssol:ETU-65064-supports-prefix

Conversation

@jonanderssol
Copy link
Copy Markdown

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]

@jonanderssol jonanderssol requested a review from a team as a code owner November 20, 2025 09:28
Copilot AI review requested due to automatic review settings November 20, 2025 09:28
@jonanderssol jonanderssol requested a review from a team as a code owner November 20, 2025 09:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 prefix field to MessageComposer that allows prepending custom text to log messages
  • Extends MessageFormatProperties with getter/setter for the prefix configuration
  • Updates the MessageComposer constructor 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);
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] ").

Suggested change
messageBuilder.append(prefix);
messageBuilder.append(prefix);
messageBuilder.append(' ');

Copilot uses AI. Check for mistakes.
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) {
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Adding the new parameter at the end to minimize breakage: MessageComposer(boolean scheme, boolean host, boolean port, boolean path, boolean query, String prefix)
  2. Deprecating the old constructor and adding a new one with the prefix parameter
  3. If breaking changes are acceptable, document this as a breaking change in the release notes

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants