-
Notifications
You must be signed in to change notification settings - Fork 81
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
Slf4j v2 backend #639
Slf4j v2 backend #639
Conversation
715449f
to
0deca17
Compare
@@ -105,7 +105,11 @@ object SLF4J { | |||
*/ | |||
override def appendCause(cause: Cause[Any]): Unit = { | |||
if (!cause.isEmpty) { | |||
throwable = FiberFailure(cause) | |||
cause match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching on a cause directly is not reliable because of nodes like or / and / stackless /e tc.
Instead, if you are trying to just "get the most important throwable", then do something like squash
or defects
or perhaps: (cause.errors.collect { case t : Throwable } ++ cause.defects).head
(or its equivalent).
Because you want to prefer an error before you look into the defects, and you want to be robust in the presence of intermediate / metadata nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that to
if (!cause.isEmpty) {
val maybeThrowable = (cause.failures.collect { case t: Throwable => t } ++ cause.defects).headOption
maybeThrowable match {
case Some(t) => throwable = t
case None => throwable = FiberFailure(cause)
}
}
can you check it? Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One quick comment to make extracting a Throwable
from a Cause
more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Please also open a ticket on ZIO to add Cause#toThrowable
that does something similar (but more efficiently).
depends on #638
fixes: #637
similar like slf4j v1 implementation (for easier migrations), but using some of new features like key value pairs
instead of MDC which have issue (like #491), as MDC using ThreadLocal
throwable/exception handling was changed to:
Cause.Die
orCause.Fail
with Throwable, that throwable is loggedzio.FiberFailure
- as it was originally in all casesTODO: