-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
log.go
108 lines (95 loc) · 2.39 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package utils
import (
"log"
"fmt"
)
var Reset = "\033[0m"
var Red = "\033[31m"
var Green = "\033[32m"
var Yellow = "\033[33m"
var Blue = "\033[34m"
var Purple = "\033[35m"
var Cyan = "\033[36m"
var Gray = "\033[37m"
var White = "\033[97m"
func Debug(message string) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
if ll <= DEBUG {
log.Println(Purple + "[DEBUG] " + message + Reset)
}
}
func Log(message string) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
if ll <= INFO {
log.Println(Blue + "[INFO] " + message + Reset)
}
}
func Warn(message string) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
if ll <= WARNING {
log.Println(Yellow + "[WARN] " + message + Reset)
}
}
func Error(message string, err error) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
errStr := ""
if err != nil {
errStr = err.Error()
}
if ll <= ERROR {
log.Println(Red + "[ERROR] " + message + " : " + errStr + Reset)
}
}
func MajorError(message string, err error) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
errStr := ""
if err != nil {
errStr = err.Error()
}
if ll <= ERROR {
log.Println(Red + "[ERROR] " + message + " : " + errStr + Reset)
}
TriggerEvent(
"cosmos.error",
"Critical Error",
"error",
"",
map[string]interface{}{
"message": message,
"error": errStr,
})
WriteNotification(Notification{
Recipient: "admin",
Title: "Server Error",
Message: message + " : " + errStr,
Level: "error",
})
}
func Fatal(message string, err error) {
ll := LoggingLevelLabels[GetMainConfig().LoggingLevel]
errStr := ""
if err != nil {
errStr = err.Error()
}
if ll <= ERROR {
log.Fatal(Red + "[FATAL] " + message + " : " + errStr + Reset)
}
}
func DoWarn(format string, a ...interface{}) string {
message := fmt.Sprintf(format, a...)
// \033[1;33m is the ANSI code for bold yellow
// \033[0m resets the color
return fmt.Sprintf("\033[1;33m[WARN] %s\033[0m", message)
}
func DoErr(format string, a ...interface{}) string {
message := fmt.Sprintf(format, a...)
// \033[1;31m is the ANSI code for bold red
// \033[0m resets the color
return fmt.Sprintf("\033[1;31m[ERROR] %s\033[0m", message)
}
func DoSuccess(format string, a ...interface{}) string {
message := fmt.Sprintf(format, a...)
// \033[1;32m is the ANSI code for bold green
// \033[0m resets the color
return fmt.Sprintf("\033[1;32m[SUCCESS] %s\033[0m", message)
}