Description
Problem Statement
The log/slog
package already released in Go 1.21. But it's unable to set for otel.SetLogger
, because it expects logr.Logger
.
Proposed Solution
OTEL uses only a few log functions (Error
, Warn
, Info
, Debug
), so a new interface can be defined, for example:
type LogAdapterer interface {
Info(msg string, keysAndValues ...interface{})
Error(err error, msg string, keysAndValues ...interface{})
Debug(msg string, keysAndValues ...interface{})
Warn(msg string, keysAndValues ...interface{})
}
In order to keep backward compatibility, a new function should be introduced, which sets this kind of logger, for example:
func SetLoggerAdapter(logger LogAdapterer)
The original otel.SetLogger
is kept for backward compatibility (but marked as deprecated), which calls otel.SetLoggerAdapter
with the exported logr
adapter.
The Error
, Warn
, Info
and Debug
functions are kept in internal/global
package, but it calls the configured logger adapter, so other code part should not be changed.
A new adapter should be created for log/slog
package, which can be passed to otel.SetLoggerAdapter
.
Alternatives
Another alternatives don't keep backward compatibility.
Prior Art
N/A
Additional Context
N/A
Metadata
Metadata
Assignees
Type
Projects
Status