/
logging.go
96 lines (76 loc) · 1.63 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
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
package common
import (
"github.com/mattn/go-colorable"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"runtime"
)
//DebugLevel Level
//InfoLevel
//WarnLevel
//ErrorLevel
//FatalLevel
//PanicLevel
//NoLevel
//Disabled
func Logging_init(Debug bool) {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if runtime.GOOS == "windows" {
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: colorable.NewColorableStdout(),
})
} else {
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stdout,
})
}
}
func LogInfo(msg string) {
log.Info().Msg(msg)
}
func LogWarn(msg string) {
log.Warn().Msg(msg)
}
func LogImprove(msg string) {
log.Debug().Msg("[Improve] " + msg)
}
func GrabUniversalLogger() *zerolog.Logger {
return &log.Logger
}
func LogInfoStructure(msg string, s interface{}, s_name string) {
log.Info().Interface(s_name, s).Msg(msg)
}
func LogDebug(msg string) {
log.Debug().Msg(msg)
}
func LogDebugString(key string, val interface{}) {
switch val.(type) {
case string:
log.Debug().Str(key, val.(string)).Msg("Variable")
case int:
log.Debug().Int(key, val.(int)).Msg("Variable")
default:
panic("LogDebugString - Unsupported type")
}
}
func LogCriticalError(msg string) {
log.Error().Msg(msg)
os.Exit(-1)
}
func LogCriticalErrorWithError(msg string, e error) {
log.Error().Err(e).Msg(msg)
os.Exit(5)
}
func LogError(msg string) {
log.Error().Msg(msg)
}
func LogErrorWithError(msg string, e error) {
log.Error().Err(e).Msg(msg)
}
func LogDebugStructure(msg string, s interface{}, s_name string) {
log.Debug().Interface(s_name, s).Msg(msg)
}