Maintenance: new logging, shorter with less deps
This commit is contained in:
@@ -23,13 +23,13 @@ func (l *looper) collectLines(wg *sync.WaitGroup, stdout, stderr <-chan string)
|
||||
}
|
||||
line, level := processLogLine(line)
|
||||
switch level {
|
||||
case logging.DebugLevel:
|
||||
case logging.LevelDebug:
|
||||
l.logger.Debug(line)
|
||||
case logging.InfoLevel:
|
||||
case logging.LevelInfo:
|
||||
l.logger.Info(line)
|
||||
case logging.WarnLevel:
|
||||
case logging.LevelWarn:
|
||||
l.logger.Warn(line)
|
||||
case logging.ErrorLevel:
|
||||
case logging.LevelError:
|
||||
l.logger.Error(line)
|
||||
}
|
||||
}
|
||||
@@ -43,18 +43,18 @@ func processLogLine(s string) (filtered string, level logging.Level) {
|
||||
switch {
|
||||
case strings.HasPrefix(filtered, "notice: "):
|
||||
filtered = strings.TrimPrefix(filtered, "notice: ")
|
||||
level = logging.InfoLevel
|
||||
level = logging.LevelInfo
|
||||
case strings.HasPrefix(filtered, "info: "):
|
||||
filtered = strings.TrimPrefix(filtered, "info: ")
|
||||
level = logging.InfoLevel
|
||||
level = logging.LevelInfo
|
||||
case strings.HasPrefix(filtered, "warn: "):
|
||||
filtered = strings.TrimPrefix(filtered, "warn: ")
|
||||
level = logging.WarnLevel
|
||||
level = logging.LevelWarn
|
||||
case strings.HasPrefix(filtered, "error: "):
|
||||
filtered = strings.TrimPrefix(filtered, "error: ")
|
||||
level = logging.ErrorLevel
|
||||
level = logging.LevelError
|
||||
default:
|
||||
level = logging.InfoLevel
|
||||
level = logging.LevelInfo
|
||||
}
|
||||
filtered = constants.ColorUnbound().Sprintf(filtered)
|
||||
return filtered, level
|
||||
|
||||
@@ -14,28 +14,28 @@ func Test_processLogLine(t *testing.T) {
|
||||
filtered string
|
||||
level logging.Level
|
||||
}{
|
||||
"empty string": {"", "", logging.InfoLevel},
|
||||
"random string": {"asdasqdb", "asdasqdb", logging.InfoLevel},
|
||||
"empty string": {"", "", logging.LevelInfo},
|
||||
"random string": {"asdasqdb", "asdasqdb", logging.LevelInfo},
|
||||
"unbound notice": {
|
||||
"[1594595249] unbound[75:0] notice: init module 0: validator",
|
||||
"init module 0: validator",
|
||||
logging.InfoLevel},
|
||||
logging.LevelInfo},
|
||||
"unbound info": {
|
||||
"[1594595249] unbound[75:0] info: init module 0: validator",
|
||||
"init module 0: validator",
|
||||
logging.InfoLevel},
|
||||
logging.LevelInfo},
|
||||
"unbound warn": {
|
||||
"[1594595249] unbound[75:0] warn: init module 0: validator",
|
||||
"init module 0: validator",
|
||||
logging.WarnLevel},
|
||||
logging.LevelWarn},
|
||||
"unbound error": {
|
||||
"[1594595249] unbound[75:0] error: init module 0: validator",
|
||||
"init module 0: validator",
|
||||
logging.ErrorLevel},
|
||||
logging.LevelError},
|
||||
"unbound unknown": {
|
||||
"[1594595249] unbound[75:0] BLA: init module 0: validator",
|
||||
"BLA: init module 0: validator",
|
||||
logging.InfoLevel},
|
||||
logging.LevelInfo},
|
||||
}
|
||||
for name, tc := range tests {
|
||||
tc := tc
|
||||
|
||||
@@ -55,7 +55,7 @@ func NewLooper(conf unbound.Configurator, settings configuration.DNS, client *ht
|
||||
},
|
||||
conf: conf,
|
||||
client: client,
|
||||
logger: logger.WithPrefix("dns over tls: "),
|
||||
logger: logger.NewChild(logging.SetPrefix("dns over tls: ")),
|
||||
username: username,
|
||||
puid: puid,
|
||||
pgid: pgid,
|
||||
|
||||
Reference in New Issue
Block a user