-
Notifications
You must be signed in to change notification settings - Fork 94
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
ZIO-2 logging (Part 1) #1038
ZIO-2 logging (Part 1) #1038
Conversation
8b47ed3
to
5c591e1
Compare
examples-zio2/src/main/scala/tofu/example/logging/ZMakeSimpleExample.scala
Outdated
Show resolved
Hide resolved
private implicit val requestIdLoggable: Loggable[String] = | ||
Loggable.stringValue.named("requestId") | ||
|
||
override def getCtx: UIO[LoggedValue] = ref.get.map(x => x) |
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.
Is there any other way to get implement this method other than that? It feels like any implementation of ContextProvider
will be doing something.something.map(x => /*implicit conversion*/ x)
. Perhaps it's better to make it ContextProvider[A: Loggable]
?
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.
ZLogs.layerPlainWithContext
is pretty now: we can provide to it any implementation of ContextProvider
.
If we make this trait as ContextProvider[A: Loggable]
, the layer will also require type-parameter which can be huge enough. For example, next PR will bring ContextProvider
with data A = Map[ZLogAnnotation[_], Any]
.
As a user, I don't want write THIS type A
, ideally I should not know anything about it. I just write two things
zioProgram.provide(
ZLogs.layerPlainWithContext, // dear tofu, give me a logger factory using ContextProvider I point next to
TofuDefaultContext.layer // I'd like to log this context, don't carry how this collected
)
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.
will be doing something.something.map(x => /implicit conversion/ x)
suggest abstract class ValueContextProvider
which do this itself
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.
suggest abstract class ValueContextProvider which do this itself
yep, that'll work
This PR copy-pastes ZIO-1 implementation with small improvements.
The docs and ZIO-Native implementation will be brought with another PR.