log4cats icon indicating copy to clipboard operation
log4cats copied to clipboard

Add some helpers for using Kleisli or IOLocal for logging context

Open wunderk1nd-e opened this issue 2 years ago • 9 comments

  • Add helpers for logging with some propagated ctx and kleisli implementation
  • Add ce3 module and iolocal instances

wunderk1nd-e avatar Aug 17 '22 12:08 wunderk1nd-e

Instead of adding a CE3 module I think we should just add a CE3 dependency to the core module. CE2 is officially sunset and there's already blocking footguns in core that can only be fixed with CE3.

  • https://github.com/typelevel/log4cats/issues/677

armanbilge avatar Aug 20 '22 04:08 armanbilge

So I had a discussion with @ChristopherDavenport on Discord wrt https://github.com/typelevel/log4cats/issues/677. Although he is supportive of adding a CE dependency to core, he still thinks anything IOLocal-based should be in a separate module.

I would expect that should be in a different module. Not core Because it's not a way I think folks expect, and the way to do it would be unsafe almost certainly. Since they will globalize. IOLocal is overspecified. And FiberLocal is a side library. So it should be a module or repo with FiberLocal which is a better abstraction then forcing everything to IO

armanbilge avatar Sep 10 '22 15:09 armanbilge

So the cats-effect-std dependency landed in core, but IOLocal would require the full cats-effect. Doing that would pull cats-effect (and IO) into all the downstream projects that limited themselves to cats-effect-std. That's a pretty good argument for a separate module.

rossabaker avatar Jan 04 '23 04:01 rossabaker

So the cats-effect-std dependency landed in core, but IOLocal would require the full cats-effect. Doing that would pull cats-effect (and IO) into all the downstream projects that limited themselves to cats-effect-std. That's a pretty good argument for a separate module.

I've updated the branch with main - any chance you could approve the workflow run? 🙏

wunderk1nd-e avatar Jan 23 '23 16:01 wunderk1nd-e

I have come to believe that almost all uses of IOLocal should have that cats.mtl.Local shape. See typelevel/cats-effect#3385. And I like the scope name: that's what Local calls it.

Should this PR then be in terms of Local, instead of offering specific instances?

armanbilge avatar Feb 20 '23 02:02 armanbilge

I would have thought so, until cats-mtl's future stability was questioned on this pull request. The uncertainty around that statement is blocking a cats-effect PR, a clear path forward on otel4s, and now this.

rossabaker avatar Feb 20 '23 02:02 rossabaker

Yeah. I know it's annoying, but might be worth pausing on this one as well until that's decided. We already have a CE dependency in log4cats core, and CE is already (technically) tied to MTL versioning, and thus so are we.

armanbilge avatar Feb 20 '23 02:02 armanbilge

If @wunderk1nd-e isn't desperate for a release on that, I think that's a sound strategy. The fact everything is being done twice is because there's a lovely type class for this if we'd accept it as a routine dependency.

rossabaker avatar Feb 20 '23 03:02 rossabaker

Is it worth it/feasible to add a plain and simple LoggerFactory.withContext, as a way of propagating context when you're passing around LoggerFactorys, or is that going to conflict the eventual implementation of this PR?

mattyjbrown avatar Mar 01 '23 15:03 mattyjbrown