typelevel / log4cats

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

Support for a safe way to defer logging on the happy path #834

Closed morgen-peschke closed 2 months ago

morgen-peschke commented 4 months ago

A "that would be nice" feature that's come up occasionally when discussing logging is the ability to log only when an error condition is encountered.

We can get basically this in tests using TestingLogger/StructuredTestingLogger and it would be really handy to be able to do this in production code as well.

I think there's a path to a reasonable implementation using Ref, but I'm not sure if there isn't a more elegant way to handle a logger's lifecycle (particularly in the context of an http4s request).

I haven't poked at how this would work with LoggerFactory, which may have it's own complications.