-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_levels.go
62 lines (56 loc) · 1.37 KB
/
log_levels.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (C) 2022, Chain4Travel AG. All rights reserved.
//
// This file is a derived work, based on ava-labs code
//
// It is distributed under the same license conditions as the
// original code from which it is derived.
//
// Much love to the original authors for their work.
package logging
import (
"github.com/sirupsen/logrus"
)
const (
trace = "trace"
debug = "debug"
info = "info"
warn = "warn"
error = "error"
fatal = "fatal"
)
/*
These are the strings forming a pseudo-"enum" of log levels that the Camino E2E tests initializer and the controller will
accept, with a mapping to the logrus log levels that will be used to actually set the logger's level
*/
var acceptableLogLevels = map[string]logrus.Level{
trace: logrus.TraceLevel,
debug: logrus.DebugLevel,
info: logrus.InfoLevel,
warn: logrus.WarnLevel,
error: logrus.ErrorLevel,
fatal: logrus.FatalLevel,
}
/*
Gets a logrus log level from the given string (which likely comes from a CLI argument), verifying that the string is
in our list of accepted log levels
*/
func LevelFromString(str string) *logrus.Level {
level, found := acceptableLogLevels[str]
if !found {
return nil
}
return &level
}
/*
Gets the list of all acceptable strings representing our log levels (used for validation)
*/
func GetAcceptableStrings() []string {
return []string{
trace,
debug,
info,
warn,
error,
fatal,
}
}