-
-
Notifications
You must be signed in to change notification settings - Fork 116
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/Logback ILoggingEvent "message" field #449
Comments
Thank you for reporting an issue. See the wiki for documentation and slack for questions. |
Can you please provide some more info? |
Exactly.
Also possible, yes. |
ok, would you like to send a PR for that or let me do the proposal? |
I'm mostly interested in the unformatted message. In case you have broader scope in mind then it is probably better if you come up with a proposal. |
I suggest that you'll do the initial PR for the unformatted message (maybe call it |
I just understood that the |
One proposal from SLF4J developers (the original comment):
What do you think about this change? |
Do you know of a way to make it accessible only to the plugin? Can the plugin work with private members? |
The compiler plugin would be manipulating the (user-written) code that calls kotlin-logging API -- it does not manipulate the kotlin-logging code. So, the API that it would call would need to be public -- users can also call the same API themselves. Some options, from the top of my head:
I would prefer the first option. |
I would like to avoid the first option. It will also cause confusion for users in other platforms (not jvm). |
That sounds interesting, I'll investigate that option. Any pointers to get me started faster? EDIT: I think I found it: https://github.com/oshai/kotlin-logging/tree/master/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/jul |
Here is my Logback backend for kotlin-logging and a proposal for how to pass in |
@neeme-praks-sympower anything left to do here? |
Context
SLF4J/Logback
ILoggingEvent
(source) 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, themessage
field contains the same formatted message asformattedMessage
, breaking the possibilities for aggregation.Proposal
Introduce a new field in
KLoggingEventBuilder
that could contain the log message template (e.g."Hello $variable!"
):LoggingEvent.message
field and the formatted log message is passed toLoggingEvent.formattedMessage
(see also Allow to pass in a "formatted message" via SLF4J LoggingEvent (in addition to "message" field) qos-ch/slf4j#437).LoggingEvent.message
and leavingLoggingEvent.formattedMessage
empty).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).The text was updated successfully, but these errors were encountered: