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

Support optional/nullable values for MDC #172

Closed
fdw opened this issue Mar 23, 2021 · 7 comments
Closed

Support optional/nullable values for MDC #172

fdw opened this issue Mar 23, 2021 · 7 comments

Comments

@fdw
Copy link
Contributor

fdw commented Mar 23, 2021

I'd like to add a value to the MDC if it exists. With the current implementation, I have to manually check this before I can call withLoggingContext. However, I'd like to pass a nullable argument that is only added to MDC if it's not null.

If you're interested, I would also try to write a PR.

@oshai
Copy link
Owner

oshai commented Mar 25, 2021

what kind of api did you have in mind?

@fdw
Copy link
Contributor Author

fdw commented Mar 26, 2021

My suggestion would be a very simple fun withLoggingContext(vararg Pair<String, String?>...) with a filter { it.value != null} or something similar.

@fdw
Copy link
Contributor Author

fdw commented Apr 1, 2021

It was so easy that I went ahead and opened a PR. Hope you don't mind :)

oshai pushed a commit that referenced this issue Apr 8, 2021
`withLoggingContext` now accepts nullable values that won't be written
to the `MDC` (and thus also don't overwrite existing values).
This might be useful if some values are not guaranteed to exist, but you
want them in the `MDC` if possible.

Issue: #172
@oshai
Copy link
Owner

oshai commented Apr 8, 2021

Released in 2.0.7. Thanks again!

@oshai oshai closed this as completed Apr 8, 2021
@fdw
Copy link
Contributor Author

fdw commented Apr 15, 2021

Quick question: I can't find a 2.0.7 release. Did I misunderstand you?

@oshai
Copy link
Owner

oshai commented Apr 18, 2021

I think it's because jcenter is not working anymore because the build was working: https://travis-ci.org/github/MicroUtils/kotlin-logging/jobs/761498773

I'll have to move to use maven central directly and only then publish again.

@fdw
Copy link
Contributor Author

fdw commented Apr 18, 2021

Ah, thank you and good luck! 🙂

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