-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
41 lines (39 loc) · 1.04 KB
/
logging.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
package foxkit
import (
"log"
"os"
"runtime"
)
func redBoldColor(message string) string {
if _, exists := os.LookupEnv("DISABLE_COLOR"); exists {
return message
} else {
return "\033[31m\033[1m" + message + "\033[m"
}
}
func boldColor(message string) string {
if _, exists := os.LookupEnv("DISABLE_COLOR"); exists {
return message
} else {
return "\033[1m" + message + "\033[m"
}
}
func ErrorFatal(name string, err error) {
if err != nil {
_, filename, line, _ := runtime.Caller(1)
log.Fatalf("[%v] [%v] [%v:%v] %v", name, redBoldColor("FATAL"), filename, line, redBoldColor(err.Error()))
}
}
func ErrorPanic(err error) {
if err != nil {
panic(err)
}
}
func LogEvent(name string, message string) {
_, filename, line, _ := runtime.Caller(1)
log.Printf("[%v] [%v] [%v:%v] %v", name, boldColor("LOG"), filename, line, boldColor(message))
}
func LogError(name string, err error) {
_, filename, line, _ := runtime.Caller(1)
log.Printf("[%v] [%v] [%v:%v] %v", name, redBoldColor("ERROR"), filename, line, redBoldColor(err.Error()))
}