log4cats
log4cats copied to clipboard
Way to change logger name
It would be nice for me to change the name of a passed Logger
instance so I can differentiate across classes.
I think a method like
def withName(s: String): Logger[F]
would do
WDYT?
These seems nice. Is anyone else sure how this translates to any backends other than slf4j?
Good question, I’ll try to prototype this in a PR
I feel that the canonical way of dealing with logger names would be passing a LoggerFactory
instance to class constructors instead of the Logger
itself. Then, a new class-related instance of Logger
is supposed to be created over there that would "latch" the class name per se.
The suggested withName
method could be an alternative approach of course but to me it seems like a leaky abstraction a bit, because one class can be passed with Logger
from another class and therefore start emit log messages on behalf of the other one.
Yup, I think a LoggerFactory
constraint is currently the best practice way to support logging. Or at least, that's what we did in http4s.
- https://github.com/http4s/http4s/pull/7122