typelevel / log4cats

Logging Tools For Interaction with cats-effect
https://typelevel.org/log4cats/
Apache License 2.0
400 stars 73 forks source link

Way to copy a logger's context onto a logger with a different name #856

Open timbertson opened 2 months ago

timbertson commented 2 months ago

I have two loggers, let's say they're named rpc and eval.

I want to handoff processing from the rpc to eval module, but my rpc logger has request info in its context, which I want to include when I make logging calls from the eval logger.

238 is one solution, I could copy my rpc logger and also name it eval. Alternatively, if there was a way to extract the context from a logger I could either pass that around detached from the original logger, or write a function which adopted the context from a passed-in logger.

timbertson commented 2 months ago

Another way to achieve this might be to have an implicit context object, which each log call accepts, and includes that context with the log statement. That way you pass around the context, and pair it with your module / class-level logger.

That would save you from having to build a fresh logger each time execution changes hands between modules. But maybe the ergonomics get awkward, as there's now 2 (or 3?) ways to inject context.