-
Notifications
You must be signed in to change notification settings - Fork 77
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
Hooks for adding custom fields #147
Comments
You could set custom values as MDC. Would that be an option for you? |
I'm not sure I understand the suggestion, it doesn't seem to apply for the fields I gave as examples. Are you suggesting that I replace all log messages like this:
with something like this?
I don't think that's enforceable across my entire codebase. I looked into doing it with a logback filter but I don't see a way to clear the values from the MDC after the message is logged. |
Actually I think I do see how this can help: I can subclass EcsEncoder and override encode() to add/remove fields from the MDC, something like:
I think this will work, thank you! I'd like to keep this request open, though, because I would still prefer a solution that didn't require going through the MDC. |
Just finished testing out the idea in my previous comment and it doesn't work - the LoggingEvent gets it's own lazily-loaded copy of the MDC which can be populated before this point (for example: when using an AsyncAppender), so this is too late to add things to the MDC. |
We could add a protected method in |
Yes, that'd be perfect |
Could you create a PR for that? |
Protected method that subclasses can override to insert arbitrary custom fields in the logback encoder. elastic#147
Protected method that subclasses can override to insert arbitrary custom fields in the logback encoder closes #147
@echatman thanks for adding this, it's perfect for my use case. However, I extended the Any ideas why?
|
Nevermind, it works now. Actually the |
I would like to use co.elastic.logging.logback.EcsEncoder but I need to be able to add some custom fields. Some examples are: Exception root cause class, exception root cause message, and raw/unformatted log message.
I tried subclassing EcsEncoder, but since everything inside encode() is just static calls to EcsJsonSerializer, and all of the fields in EcsEncoder are private, I can't find any way to accomplish this.
The text was updated successfully, but these errors were encountered: