-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
65 lines (56 loc) · 1.12 KB
/
log.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
63
64
65
package rotdetector
import (
"log"
"os"
)
const (
DEBUG = iota
INFO
WARNING
ERROR
)
var (
logger = log.New(os.Stdout, "rotdetector: ", log.Ldate|log.Ltime|log.Lshortfile)
// logLevel is the current logging level.
logLevel = INFO
Reset = "\033[0m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Magenta = "\033[35m"
Cyan = "\033[36m"
Gray = "\033[37m"
)
// SetLogLevel sets the logging level.
func SetLogLevel(level int) {
logLevel = level
}
// Debug logs a message at the DEBUG level.
func Debug(v ...interface{}) {
if logLevel <= DEBUG {
logger.SetPrefix("DEBUG: ")
logger.Println(v...)
}
}
// Info logs a message at the INFO level.
func Info(v ...interface{}) {
if logLevel <= INFO {
logger.SetPrefix("INFO: ")
logger.Println(v...)
}
}
// Warning logs a message at the WARNING level.
func Warning(v ...interface{}) {
if logLevel <= WARNING {
logger.SetPrefix("WARNING: ")
logger.Println(v...)
}
}
// Error logs a message at the ERROR level.
func Error(v ...interface{}) {
if logLevel <= ERROR {
logger.SetPrefix("ERROR: ")
logger.Println(v...)
}
}