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

When an error occurs in Log message invocation then log it as an ERROR #160

Closed
kemalizing opened this issue Dec 1, 2020 · 5 comments
Closed

Comments

@kemalizing
Copy link

Hi,

We are using kotlin-logging on many services on production. Today we figured out that if a message lambda fails, that incident is logged with the initial logging level, while it is actually an error. Which leads to some unexpected behavior.

Basically I'm speaking about this log "Log message invocation failed: $e" coming from toStringSafe method.

Is it possible to log that exception in ERROR level?

Thanks.
Kind regards

@oshai
Copy link
Owner

oshai commented Dec 2, 2020

For reference, this is the original issue it was added: #22

It's not so obvious how to implement that, and what the logging level should be (error? warn?) because this methos is just returning a string.
What I suggest is adding a jvm param to throw the exception, then users can do whatever they decide to do with it.
What do you think?

@kemalizing
Copy link
Author

Thanks for the quick response.

I like your idea of throwing an exception. If I've a problem in my code, the lambda in this case, I'd like to see it as an exception in my service, totally makes sense.

oshai added a commit that referenced this issue Dec 6, 2020
in case system property is defined: kotlin-logging.throwOnMessageError
@oshai
Copy link
Owner

oshai commented Dec 6, 2020

@kemalizing - please let me know if #161 PR looks as you expect.

@kemalizing
Copy link
Author

kemalizing commented Dec 7, 2020

Looks good, thanks for the quick fix! Also, would be nice to mention it in your documentation.

@oshai oshai closed this as completed in 27f93f9 Dec 14, 2020
@oshai
Copy link
Owner

oshai commented Dec 14, 2020

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