I'm working on a Cortex Exporter and noticed that there isn't much consistency as to what logging package is used across the various components (instrumentation plugins, exporters, etc.). As mentioned by @MrAlias on Gitter, this should probably be configurable by the end user. The standard log package would probably be a smart default, but I'd like to start a discussion on what the default package should be and how we can make this configurable. Thanks.
A pattern I've had success with in the past is to define a simple interface and provide accessors that fallback to the stdlib log package if no implementation is provided.
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
// etc., maybe Fatal/Fatalf
}
func FromContext(ctx context.Context) Logger {...}
I'd really like to be able to attach labels/fields to a log entry, but I'm not sure there's any consistent interface that could be expected to be common between log, logrus, zap, and any other likely candidate for a Logger implementation.
Most helpful comment
A pattern I've had success with in the past is to define a simple interface and provide accessors that fallback to the stdlib
logpackage if no implementation is provided.I'd really like to be able to attach labels/fields to a log entry, but I'm not sure there's any consistent interface that could be expected to be common between
log,logrus,zap, and any other likely candidate for aLoggerimplementation.