blob: 97dccb205223eecccec7e4dff9d47e7f6e176524 (
plain)
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
45
46
47
48
49
50
51
52
53
54
|
// SPDX-License-Identifier: GPL-3.0-or-later
package logger
import (
"log/slog"
"strings"
)
const (
levelNotice = slog.Level(2)
levelDisable = slog.Level(99)
)
var (
customLevels = map[slog.Leveler]string{
levelNotice: "NOTICE",
}
customLevelsTerm = map[slog.Leveler]string{
levelNotice: "\u001B[34m" + "NTC" + "\u001B[0m",
}
)
var Level = &level{lvl: &slog.LevelVar{}}
type level struct {
lvl *slog.LevelVar
}
func (l *level) Enabled(level slog.Level) bool {
return level >= l.lvl.Level()
}
func (l *level) Set(level slog.Level) {
l.lvl.Set(level)
}
func (l *level) SetByName(level string) {
// https://github.com/netdata/netdata/tree/master/src/libnetdata/log#log-levels
switch strings.ToLower(level) {
case "err", "error":
l.lvl.Set(slog.LevelError)
case "warn", "warning":
l.lvl.Set(slog.LevelWarn)
case "notice":
l.lvl.Set(levelNotice)
case "info":
l.lvl.Set(slog.LevelInfo)
case "debug":
l.lvl.Set(slog.LevelDebug)
case "emergency", "alert", "critical":
l.lvl.Set(levelDisable)
}
}
|