-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
77 lines (66 loc) · 1.41 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
66
67
68
69
70
71
72
73
74
75
76
77
package rogue
import (
"fmt"
"log"
)
type category int
const (
FATAL = "FATAL"
ERROR = "ERROR"
WARNING = "WARNING"
INFO = "INFO"
)
func PrintLog(category string, newline bool, text ...string) {
content := mergeText(text...)
if newline {
fmt.Printf("\n")
}
switch category {
case FATAL:
log.Println(Red("[ROGUE:FATAL]"), Yellow(content))
case ERROR:
log.Println(Red("[ROGUE:ERROR]"), Yellow(content))
case WARNING:
log.Println(Yellow("[ROGUE:WARNING]"), LightGray(content))
case INFO:
fmt.Println(Blue("[ROGUE:INFO]"), LightGray(content))
default:
if category == "" {
fmt.Println(Blue("[ROGUE]"), LightGray(content))
} else {
fmt.Println(Blue("[ROGUE:"+category+"]"), LightGray(content))
}
}
}
func mergeText(text ...string) string {
var content string
for _, t := range text {
content += t
}
return content
}
func FatalError(err error, text ...string) {
if err != nil {
PrintLog(FATAL, false, text...)
} else {
content := mergeText(text...)
PrintLog(FATAL, false, content+": "+err.Error())
}
}
func Error(err error, text ...string) {
if err != nil {
PrintLog(ERROR, false, text...)
} else {
content := mergeText(text...)
PrintLog(ERROR, false, content+": "+err.Error())
}
}
func Warning(text ...string) {
PrintLog(WARNING, false, text...)
}
func Info(text ...string) {
PrintLog(INFO, false, text...)
}
func Log(text ...string) {
PrintLog("", false, text...)
}