/
log.go
44 lines (34 loc) · 872 Bytes
/
log.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
42
43
44
package trails
import (
"strings"
"log/slog"
)
const (
LogKindKey = "kind"
LogMaskVal = "xxxxxx"
)
var (
AppLogKind = slog.StringValue("app")
HTTPLogKind = slog.StringValue("http")
WorkerLogKind = slog.StringValue("worker")
// MaskedLogValue is a convenience [golang.org/x/exp/slog.Value]
// to be used in implementations of [golang.org/x/exp/slog.LogValuer]
// to hide sensitive data from log messages.
MaskedLogValue = slog.StringValue(LogMaskVal)
)
// NewLogLevel translates val into a [golang.org/x/exp/slog.Level]
func NewLogLevel(val string) slog.Level {
if strings.EqualFold("DEBUG", val) {
return slog.LevelDebug
}
if strings.EqualFold("INFO", val) {
return slog.LevelInfo
}
if strings.EqualFold("WARN", val) {
return slog.LevelWarn
}
if strings.EqualFold("ERROR", val) {
return slog.LevelError
}
return slog.LevelInfo
}