-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathGlobalLogger.go
56 lines (47 loc) · 1.09 KB
/
GlobalLogger.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
package global
import (
"github.com/TwinProduction/go-color"
"log"
)
// Global logger module for displaying the logs to the terminal
type LoggerInterface interface {
LogInfo()
LogWarning()
LogError()
}
type Logger struct {
Message string
}
const (
StatusError = "StatusError"
StatusInfo = "StatusInfo"
StatusWarning = "StatusWarning"
)
// Log gets the log message and the status selector
// The log flag is chosen and color coded based on the status received
func (logger *Logger) Log(message string, status string) {
logger.Message = message
switch status {
case StatusInfo:
logger.LogInfo()
break
case StatusWarning:
logger.LogWarning()
break
case StatusError:
logger.LogError()
break
default:
logger.LogInfo()
}
}
func (logger *Logger) LogInfo() {
log.Printf("%v[INFO]: %v%v\n", color.Cyan, color.Reset, logger.Message)
}
func (logger *Logger) LogWarning() {
log.Printf("%v[WARNING]: %v%v\n", color.Yellow, color.Reset, logger.Message)
}
func (logger *Logger) LogError() {
//debug.PrintStack()
log.Printf("%v[ERROR]: %v%v\n", color.Red, color.Reset, logger.Message)
}