-
Notifications
You must be signed in to change notification settings - Fork 82
Update #676: Adopt cats.mtl.Local for Logging Context and IOLocal #905
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
Conversation
@armanbilge would you please look at my changes. 😊 |
@morgen-peschke would you be able to take a look? 🙏 |
@morgen-peschke would you please review my changes 😊 |
object IOLocalHelpers { | ||
def loggerWithContext( | ||
sl: SelfAwareStructuredLogger[IO] | ||
)(implicit local: Local[IO, Map[String, String]]): SelfAwareStructuredLogger[IO] = | ||
SelfAwareStructuredLogger.withContextF(sl)(local.ask) | ||
|
||
def factoryWithContext( | ||
lf: LoggerFactory[IO] | ||
)(implicit local: Local[IO, Map[String, String]]): LoggerFactory[IO] = | ||
LoggerFactory.withContextF(lf)(local.ask) |
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.
question: given this operates on Local[IO
, can we make it an F[_]
and move the whole thing back to the core module?
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.
also, would love to see these as extension functions. .withLocalContext
, maybe? (they can both be named the same, as they'd be called on different types)
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.
Thank you for the review.
Based on your review
I must delete this file
and create one in the core/src/main/scala/org/typelevel/log4cats/LocalHelpers.scala (core module)
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.
sounds about right :)
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.
Hey, I have made some changes as you suggested
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.
Just build.sbt I think, looks like CI is generated from that.
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.
Yes, I will update the build.sbt, actually, while doing upstream with the latest, I accidentally removed ce3 from ci.yml. Then, looking at the previous commit, I added it manually. Thank you for the clarification.
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 see there is a command for generating workflow sbt githubWorkflowGenerate
, now I learned it😊
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.
Indeed - if you run inspect githubWorkflowGenerate
in sbt, it should tell you about the name of the file it comes from. And based on that you might be able to infer that it's from https://github.com/typelevel/sbt-typelevel/ - good to know in the future, in case you need to work with GH workflows via sbt more.
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.
Thanks for pointing that out! I’ll check out inspect githubWorkflowGenerate
in sbt for more details. Good to know about the connection to sbt-typelevel
, definitely helpful for working with GitHub workflows in the future. Appreciate the tip! 😊
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 have a few issues with this API design:
- the
Local
is not bundled with theLogger
, so it is easy to forget to propagate/expose it with theLogger
. also with the typeLocal[F, Map[String, String]]
, it is not necessarily obvious what it is with it not being bundled with theLogger
. - it is possible to forget to attach the
Local
to theLogger
, or to pass the wrongLocal
along with theLogger
and have theLocal
that is passed around not affect theLogger
. - it is difficult (though not impossible) to have additional context that's not in the
Local
automatically added to every logging operation, such as one might want to do withtraceId
andspanId
for a span. - exposing the
Local
directly allows users to remove existing context, which was up until now not possible and is almost certainly undesirable. it would be better to expose only methods that allow users to have certain context added for a certain effect/scope. - this is a more opinionated concern, but: this design encourages the use of the inflexible
StructuredLogger
API—the API whose inflexibility is the primary reason for this change. the user is always passing around aSelfAwareStructuredLogger
, and particularly users who are not familiar with the local semantics are likely to ignore theLocal
and use the sub-optimaladdContext
methods on theLogger
. I would much prefer if there was a separateLocalLogger
API that exposed a (deprecated) method to access the underlyingSelfAwareStructuredLogger
, for gradual migration purposes.
there is also an implementation issue that the logging methods should check is<Level>Enabled
before logging so that they're nearly a no-op when disabled, but that's fairly easy (if tedious) to fix and is not externally visible.
I designed #909 to solve these API shortcomings.
Hello @NthPortal , |
@Jay-Lokhande I'll try |
Hello, |
this PR is continuation of #676, which have some modification since CE v3.6.0 was released dependency on Cats MTL and a Local instance for IOLocal
I have removed
ce3/shared/src/main/scala/org/typelevel/log4cats/ce3/IOLocalHelpers.scala
and moved implementation to the core module