log4cats icon indicating copy to clipboard operation
log4cats copied to clipboard

Way to change logger name

Open cquiroz opened this issue 5 years ago • 4 comments

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?

cquiroz avatar Oct 02 '19 15:10 cquiroz

These seems nice. Is anyone else sure how this translates to any backends other than slf4j?

ChristopherDavenport avatar Oct 16 '19 22:10 ChristopherDavenport

Good question, I’ll try to prototype this in a PR

cquiroz avatar Oct 17 '19 10:10 cquiroz

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.

satorg avatar Aug 09 '23 23:08 satorg

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

armanbilge avatar Aug 10 '23 02:08 armanbilge