-
Notifications
You must be signed in to change notification settings - Fork 2
/
loggers.go
72 lines (55 loc) · 1.26 KB
/
loggers.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
package main
import (
"fmt"
"github.com/fatih/color"
)
const (
FATAL = "FATAL"
ERROR = "ERROR"
WARN = "WARNING"
INFO = "INFO"
DEBUG = "DEBUG"
TRACE = "TRACE"
)
type ILoggers interface {
Debug(message interface{})
Info(message interface{})
Warn(message interface{})
Error(message interface{})
Fatal(message interface{})
Trace(message interface{})
Log(level string, message interface{})
}
type Loggers struct{}
func NewLogger() ILoggers {
return &Loggers{}
}
func (loggers *Loggers) Debug(message interface{}) {
loggers.Log(DEBUG, message)
}
func (loggers *Loggers) Info(message interface{}) {
loggers.Log(INFO, message)
}
func (loggers *Loggers) Warn(message interface{}) {
loggers.Log(WARN, message)
}
func (loggers *Loggers) Error(message interface{}) {
loggers.Log(ERROR, message)
}
func (loggers *Loggers) Fatal(message interface{}) {
loggers.Log(FATAL, message)
}
func (loggers *Loggers) Trace(message interface{}) {
loggers.Log(TRACE, message)
}
func (loggers *Loggers) Log(level string, message interface{}) {
Spinner.Stop()
c := color.New(color.FgWhite)
if level == ERROR {
c = color.New(color.FgRed, color.Bold)
}
if level == INFO {
c = color.New(color.FgGreen, color.Bold)
}
_, _ = c.Println(fmt.Sprintf("⇨ %s", message))
}