(no title)
tastysandwich | 2 years ago
I've got a few packages that accept a basic logger interface, eg:
type debugLogger interface {
Debugf(format string, args ...any)
}
type MyThing struct {
logger debugLogger
}
func New(logger debugLogger) *MyThing {
return &MyThing{logger}
}
I'd love to switch to slog but I'll have to v2 these packages now.
crdrost|2 years ago
It's like when you're trying to internationalize, you want to emit as constant of a string as reasonably practical, so that it can be straightforwardly matched and substituted into a different language. Except in this case that different language is regexes being used to change the thing into a SQL statement to fix the mess (or whatever).
So much easier to say "stop trying to Sprintf your logs, just add the values as key-value pairs at the end of the function call."
physicles|2 years ago