forked from sandia-minimega/minimega
-
Notifications
You must be signed in to change notification settings - Fork 1
/
level.go
62 lines (54 loc) · 1009 Bytes
/
level.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 (2017) Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
package minilog
import (
"errors"
"fmt"
)
type Level int
// Log levels supported:
// DEBUG -> INFO -> WARN -> ERROR -> FATAL
const (
_ Level = iota
DEBUG
INFO
WARN
ERROR
FATAL
)
// ParseLevel returns the log level from a string.
func ParseLevel(s string) (Level, error) {
switch s {
case "debug":
return DEBUG, nil
case "info":
return INFO, nil
case "warn":
return WARN, nil
case "error":
return ERROR, nil
case "fatal":
return FATAL, nil
}
return -1, errors.New("invalid log level")
}
func (l *Level) Set(s string) (err error) {
*l, err = ParseLevel(s)
return
}
func (l Level) String() string {
switch l {
case DEBUG:
return "debug"
case INFO:
return "info"
case WARN:
return "warn"
case ERROR:
return "error"
case FATAL:
return "fatal"
}
return fmt.Sprintf("Level(%d)", l)
}