-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
45 lines (37 loc) · 989 Bytes
/
logger.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
package simple
import (
"log"
)
const (
INFO = "info"
DEBUG = "debug"
WARN = "warn"
ERROR = "error"
TRACE = "trace"
)
type Logger struct {
Level string
}
func (logger Logger) Debug(message string) {
if logger.Level == DEBUG || logger.Level == TRACE {
log.Printf("\x1b[1;92m [%s] \x1b[0m : %s", "DEBUG", message)
}
}
func (logger Logger) Error(message string) {
log.Printf("\x1b[1;91m [%s] \x1b[0m : %s", "ERROR", message)
}
func (logger Logger) Warn(message string) {
if logger.Level == WARN || logger.Level == DEBUG || logger.Level == INFO || logger.Level == TRACE {
log.Printf("\x1b[1;93m [%s] \x1b[0m : %s", "WARN", message)
}
}
func (logger Logger) Trace(message string) {
if logger.Level == TRACE {
log.Printf("\x1b[1;96m [%s] \x1b[0m : %s", "TRACE", message)
}
}
func (logger Logger) Info(message string) {
if logger.Level == INFO || logger.Level == DEBUG || logger.Level == TRACE {
log.Printf("\x1b[1;94m [%s] \x1b[0m : %s", "INFO", message)
}
}