-
Notifications
You must be signed in to change notification settings - Fork 0
/
gokitlog.go
38 lines (31 loc) · 916 Bytes
/
gokitlog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package logger
import (
"context"
"log/slog"
"strings"
gokitlog "github.com/go-kit/log"
)
type logFunc func(ctx context.Context, msg string, keysAndValues ...interface{})
func (l logFunc) Log(keyvals ...interface{}) error {
ctx := SourceContext(context.Background(), CallerSource(2))
l(ctx, "", keyvals...)
return nil
}
// logger.NewLogger(os.Stdout, logger.WithJSON(true))
// logger := logger.NewGoKitLogger("info")
func NewGoKitLogger(level string) gokitlog.Logger {
var logFunc logFunc
switch {
case strings.EqualFold(level, LevelDebug):
logFunc = slog.Default().DebugContext
case strings.EqualFold(level, LevelInfo):
logFunc = slog.Default().InfoContext
case strings.EqualFold(level, LevelWarn):
logFunc = slog.Default().WarnContext
case strings.EqualFold(level, LevelError):
logFunc = slog.Default().ErrorContext
default:
logFunc = slog.Default().InfoContext
}
return logFunc
}