Logging: Use slog adapter for go-kit/log with App SDK logger (#99740)

* feat: use slog adapter for go-kit/log

The adapter library is Apache-2.0, which is compatible with AGPL-3.0 as a dependency.

The adapter library outputs a little more info than we'd like, but rather a couple fields too many than it outputting
ERROR logs as INFO.

* feat: update dependencies

* chore: attribute ownership of dependency

* refactor: move require

* chore: make update-workspace
This commit is contained in:
Mariell Hoversholm
2025-01-29 14:59:37 +01:00
committed by GitHub
parent 1087ed623f
commit baaff6296f
7 changed files with 19 additions and 2 deletions
+10 -2
View File
@@ -20,6 +20,7 @@ import (
"github.com/go-kit/log/level"
"github.com/go-stack/stack"
"github.com/mattn/go-isatty"
sloggokit "github.com/tjhop/slog-gokit"
"gopkg.in/ini.v1"
"github.com/grafana/grafana-app-sdk/logging"
@@ -53,6 +54,7 @@ func init() {
}
logger := level.NewFilter(format(os.Stderr), level.AllowInfo())
root = newManager(logger)
initAppSDKLogger(logger)
RegisterContextualLogProvider(func(ctx context.Context) ([]any, bool) {
pFromCtx := ctx.Value(logParamsContextKey{})
@@ -61,8 +63,6 @@ func init() {
}
return nil, false
})
logging.DefaultLogger = logging.NewSLogLogger(slog.Default().Handler())
}
// logManager manage loggers
@@ -112,6 +112,8 @@ func (lm *logManager) initialize(loggers []logWithFilters) {
lm.loggersByName[name].Swap(&compositeLogger{loggers: ctxLoggers})
}
initAppSDKLogger(lm.ConcreteLogger)
}
func (lm *logManager) New(ctx ...any) *ConcreteLogger {
@@ -548,3 +550,9 @@ func SetupConsoleLogger(level string) error {
return nil
}
func initAppSDKLogger(gkl gokitlog.Logger) {
// We need to allow Debug logs here. go-kit/log does not support sharing the level we're using.
// TODO: Refactor such that we can pass in a level in a more appropriate manner.
logging.DefaultLogger = logging.NewSLogLogger(sloggokit.NewGoKitHandler(gkl, slog.LevelDebug))
}