-
Notifications
You must be signed in to change notification settings - Fork 1
/
default_logger.go
41 lines (33 loc) · 883 Bytes
/
default_logger.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
39
40
41
package stableinterfaces
import (
"context"
"log"
"log/slog"
"os"
)
type (
DefaultLogger struct{}
)
func (dl *DefaultLogger) logLevel(level slog.Level, msg string, err error) {
if err != nil {
slog.LogAttrs(context.Background(), level, msg, slog.String("err", err.Error()))
return
}
log.Println(level, msg)
}
func (dl *DefaultLogger) Debug(msg string) {
dl.logLevel(slog.LevelDebug, msg, nil)
}
func (dl *DefaultLogger) Info(msg string) {
dl.logLevel(slog.LevelInfo, msg, nil)
}
func (dl *DefaultLogger) Warn(msg string, err error) {
dl.logLevel(slog.LevelWarn, msg, err)
}
func (dl *DefaultLogger) Error(msg string, err error) {
dl.logLevel(slog.LevelError, msg, nil)
}
func (dl *DefaultLogger) Fatal(msg string, err error) {
slog.LogAttrs(context.Background(), slog.LevelError, msg, slog.Bool("FATAL", true), slog.String("err", err.Error()))
os.Exit(1)
}