summaryrefslogtreecommitdiff
path: root/internal/io/dlog/level.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-10-21 21:28:49 +0300
committerPaul Buetow <pbuetow@mimecast.com>2021-10-21 21:28:49 +0300
commitf4207a55f71bfbcfdc532d5cdd3befaa3474a157 (patch)
treeea5e4a2d2a67035f645bdee496ae55a52034178a /internal/io/dlog/level.go
parentd80d6070557e3a800e3a54967af9eced518f116b (diff)
parent739205206d63bf42f4e843b39d04d4c8cd8207c3 (diff)
merge develop
Diffstat (limited to 'internal/io/dlog/level.go')
-rw-r--r--internal/io/dlog/level.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/internal/io/dlog/level.go b/internal/io/dlog/level.go
new file mode 100644
index 0000000..05d9ed9
--- /dev/null
+++ b/internal/io/dlog/level.go
@@ -0,0 +1,84 @@
+package dlog
+
+import (
+ "fmt"
+ "strings"
+)
+
+type level int
+
+// Available log levels.
+const (
+ None level = iota
+ Fatal level = iota
+ Error level = iota
+ Warn level = iota
+ Info level = iota
+ Default level = iota
+ Verbose level = iota
+ Debug level = iota
+ Devel level = iota
+ Trace level = iota
+ All level = iota
+)
+
+var allLevels = []level{Fatal, Error, Warn, Info, Default, Verbose, Debug,
+ Devel, Trace, All}
+
+func newLevel(l string) level {
+ switch strings.ToLower(l) {
+ case "none":
+ return None
+ case "fatal":
+ return Fatal
+ case "error":
+ return Error
+ case "warn":
+ return Warn
+ case "info":
+ return Info
+ case "":
+ fallthrough
+ case "default":
+ return Default
+ case "verbose":
+ return Verbose
+ case "debug":
+ return Debug
+ case "devel":
+ return Devel
+ case "trace":
+ return Trace
+ case "all":
+ return All
+ }
+ panic(fmt.Sprintf("Unknown log level %s, must be one of: %v", l, allLevels))
+}
+
+func (l level) String() string {
+ switch l {
+ case None:
+ return "NONE"
+ case Fatal:
+ return "FATAL"
+ case Error:
+ return "ERROR"
+ case Warn:
+ return "WARN"
+ case Info:
+ return "INFO"
+ case Default:
+ return "DEFAULT"
+ case Verbose:
+ return "VERBOSE"
+ case Debug:
+ return "DEBUG"
+ case Devel:
+ return "DEVEL"
+ case Trace:
+ return "TRACE"
+ case All:
+ return "ALL"
+ }
+ panic("Unknown log level " + fmt.Sprintf("%d", l))
+}