Files
grafana/apps/alerting/historian/pkg/app/logutil/logging.go
T
Steve Simpson 7aa77af7c4 Alerting: Implement notification history query endpoint. (#114736)
Implements the /notification/query endpoint on the historian app. Note that it
does not apply any RBAC right now, that will be a follow up commit.

We have to use a go-kit logger in grafana/alerting, so an adapter is needed.
Going from go-kit to slog is a bit hairy but works well enough.
2025-12-04 13:26:09 +01:00

63 lines
1.1 KiB
Go

package logutil
import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/grafana-app-sdk/logging"
)
func ToGoKitLogger(logger logging.Logger) log.Logger {
return &sdk2gkLogger{logger: logger}
}
type sdk2gkLogger struct {
logger logging.Logger
}
func (s *sdk2gkLogger) Log(keyvals ...interface{}) error {
var (
outMsg = ""
outLevel = interface{}(level.InfoValue())
outKeyvals = []interface{}{}
)
if len(keyvals) == 0 {
s.logger.Info("")
return nil
}
if len(keyvals)%2 == 1 {
keyvals = append(keyvals, nil)
}
for i := 0; i < len(keyvals); i += 2 {
k, v := keyvals[i], keyvals[i+1]
if keyvals[i] == "msg" {
outMsg = v.(string)
continue
}
if k == level.Key() {
outLevel = v
continue
}
outKeyvals = append(outKeyvals, k)
outKeyvals = append(outKeyvals, v)
}
switch outLevel {
case level.DebugValue():
s.logger.Debug(outMsg, outKeyvals...)
case level.InfoValue():
s.logger.Info(outMsg, outKeyvals...)
case level.WarnValue():
s.logger.Warn(outMsg, outKeyvals...)
case level.ErrorValue():
s.logger.Error(outMsg, outKeyvals...)
}
return nil
}