/
log.go
110 lines (89 loc) · 1.89 KB
/
log.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package common
import (
"fmt"
"github.com/op/go-logging"
"log"
"os"
)
type DebugLog int
const (
PANIC = iota
FATAL
ERROR
WARNING
INFO
DEBUG
)
var (
DebugLevel DebugLog = INFO
logger = logging.MustGetLogger("avege")
format = logging.MustStringFormatter(
"%{color}%{time:15:04:05.000} %{level:.1s} ▶%{color:reset} %{message}",
)
)
type Password string
func (p Password) Redacted() interface{} {
return logging.Redact(string(p))
}
func init() {
backend := logging.NewLogBackend(os.Stdout, "", 0)
backendFormatter := logging.NewBackendFormatter(backend, format)
// Set the backends to be used.
logging.SetBackend(backendFormatter)
}
func Panicf(format string, args ...interface{}) {
logger.Panicf(format, args...)
}
func Fatalf(format string, args ...interface{}) {
if DebugLevel >= FATAL {
logger.Fatalf(format, args...)
}
}
func Errorf(format string, args ...interface{}) {
if DebugLevel >= ERROR {
logger.Errorf(format, args...)
}
}
func Warningf(format string, args ...interface{}) {
if DebugLevel >= WARNING {
logger.Warningf(format, args...)
}
}
func Infof(format string, args ...interface{}) {
if DebugLevel >= INFO {
logger.Infof(format, args...)
}
}
func Debugf(format string, args ...interface{}) {
if DebugLevel >= DEBUG {
logger.Debugf(format, args...)
}
}
func Panic(args ...interface{}) {
log.Panicln(args...)
}
func Fatal(args ...interface{}) {
if DebugLevel >= FATAL {
logger.Fatal(fmt.Sprintln(args...))
}
}
func Error(args ...interface{}) {
if DebugLevel >= ERROR {
logger.Error(fmt.Sprintln(args...))
}
}
func Warning(args ...interface{}) {
if DebugLevel >= WARNING {
logger.Warning(fmt.Sprintln(args...))
}
}
func Info(args ...interface{}) {
if DebugLevel >= INFO {
logger.Info(fmt.Sprintln(args...))
}
}
func Debug(args ...interface{}) {
if DebugLevel >= DEBUG {
logger.Debug(fmt.Sprintln(args...))
}
}