You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As someone else pointed out in this issue #397, the class that shows up in traces reflects where the logger was instantiated, usually the main class of the application. In many applications, it is however desirable to have several loggers, each with a name reflecting a particular portion of code. This makes it easier to spot where an issue comes from, and allows logging backends to be configured on a per-class basis.
However, creating multiple loggers and passing them around can be a rather frustrating experience. Having multiple loggers means you have to give up using implicits to pass them around. I came up with a solution to address this issue, and believe this could be a nice improvement for this library.
The idea is to use a phantom type to bind a logger instance to a single class, and optionally use a ClassTag to conveniently instantiate named loggers. There are code examples in the repository :)
I haven't yet published the work as a library, and I am willing to open a PR to include it directly in log4cats, if the maintainers find it desirable :)
Cheers, and thank you for your work
The text was updated successfully, but these errors were encountered:
This way we don't lose the actual subtype of the logger (SelfAwareStructuredLogger). The drawback is that a function asking for SelfAwareStructuredLogger[F] would happily accept any of these. Though I don't know how often this would come up.
Also, #421 solves the same issue with a different set of tradeoffs.
@nigredo-tori thank you for your answer!
The type tags solution seems nice, I think me team is going to use that for now, it's probably nicer not to use a more generic tool.
Maybe this approach could be documented in the README of this library ? This feels like a fairly common use case.
Hello :)
As someone else pointed out in this issue #397, the class that shows up in traces reflects where the logger was instantiated, usually the main class of the application. In many applications, it is however desirable to have several loggers, each with a name reflecting a particular portion of code. This makes it easier to spot where an issue comes from, and allows logging backends to be configured on a per-class basis.
However, creating multiple loggers and passing them around can be a rather frustrating experience. Having multiple loggers means you have to give up using implicits to pass them around. I came up with a solution to address this issue, and believe this could be a nice improvement for this library.
The idea is to use a phantom type to bind a logger instance to a single class, and optionally use a ClassTag to conveniently instantiate named loggers. There are code examples in the repository :)
I haven't yet published the work as a library, and I am willing to open a PR to include it directly in log4cats, if the maintainers find it desirable :)
Cheers, and thank you for your work
The text was updated successfully, but these errors were encountered: