-
Notifications
You must be signed in to change notification settings - Fork 1
/
yoctog.go
58 lines (48 loc) · 1.03 KB
/
yoctog.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
package yoctog
import (
"fmt"
"log"
)
// Level is the level of logging
type Level int8
// Log levels
const (
LevelDebug Level = 1 + iota
LevelInfo
LevelWarn
LevelError
LevelAllSuppress
)
var logLevel = LevelDebug
// Debug are output debug level message
func Debug(v ...interface{}) {
if logLevel <= LevelDebug {
logger(append([]interface{}{"[DEBUG]"}, v...)...)
}
}
// Info are output information level message
func Info(v ...interface{}) {
if logLevel <= LevelInfo {
logger(append([]interface{}{"[INFO]"}, v...)...)
}
}
// Warn are output warning level message
func Warn(v ...interface{}) {
if logLevel <= LevelWarn {
logger(append([]interface{}{"[WARN]"}, v...)...)
}
}
// Error are output error level message
func Error(v ...interface{}) {
if logLevel <= LevelError {
logger(append([]interface{}{"[ERROR]"}, v...)...)
}
}
// logger are Output wrapper
func logger(v ...interface{}) {
_ = log.Output(3, fmt.Sprintln(v...))
}
// SetLogLevel is set the log output level
func SetLogLevel(level Level) {
logLevel = level
}