Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KLogger does not properly populate SLF4J ILoggingEvent "message" field #449

Open
neeme-praks-sympower opened this issue Oct 14, 2024 · 2 comments

Comments

@neeme-praks-sympower
Copy link

Context

SLF4J ILoggingEvent has two important fields / getter methods:

  • message - contains the message template (e.g. "Hello {}!")
  • formattedMessage - contains the final formatted/merged log message (e.g. "Hello world!")

This distinction is useful -- for example, we use this to aggregate log messages.

Issue

KLogger relies on Kotlin string interpolation and as a result, the message field contains the same formatted message as formattedMessage, breaking the possibilities for aggregation.

Proposal

Introduce a new field in KLoggingEventBuilder that could contain the log message template (e.g. "Hello $variable!"):

  • in case this field is filled, it is passed as-is to SLF4J ILoggingEvent.message field.
  • in case this field is not filled, the current behaviour is followed (using the formatted message).

This will make it easier for me to implement something on top of KLogger to fill that field properly (I'm thinking of implementing a Kotlin compiler plugin).

Copy link

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

@oshai
Copy link
Owner

oshai commented Oct 16, 2024

Can you please provide some more info?
You mean that the un-formatted message will be added by the compiler plugin? if so, sounds like an interesting idea. In the past I thought of using a compiler plugin to add line numbers, file name, etc'. But never implemented it.

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

No branches or pull requests

2 participants