-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglog.go
145 lines (113 loc) · 3.52 KB
/
glog.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package glog
import (
"fmt"
"math"
"os"
"sync"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
)
var maxLevel Level = math.MaxInt32
var logger = log.NewNopLogger()
var mu = sync.Mutex{}
// SetLogger redirects glog logging to the given logger.
// It must be called prior any call to glog.
func SetLogger(l log.Logger) {
mu.Lock()
logger = l
mu.Unlock()
}
// ClampLevel clamps the leveled logging at the specified value.
// It must be called prior any call to glog.
func ClampLevel(l Level) {
mu.Lock()
maxLevel = l
mu.Unlock()
}
type Level int32
type Verbose bool
func V(level Level) Verbose { return level <= maxLevel }
func (v Verbose) Info(args ...interface{}) {
if v {
level.Debug(logger).Log("func", "Verbose.Info", "msg", fmt.Sprint(args...))
}
}
func (v Verbose) Infoln(args ...interface{}) {
if v {
level.Debug(logger).Log("func", "Verbose.Infoln", "msg", fmt.Sprint(args...))
}
}
func (v Verbose) Infof(format string, args ...interface{}) {
if v {
level.Debug(logger).Log("func", "Verbose.Infof", "msg", fmt.Sprintf(format, args...))
}
}
func Info(args ...interface{}) {
level.Debug(logger).Log("func", "Info", "msg", fmt.Sprint(args...))
}
func InfoDepth(depth int, args ...interface{}) {
level.Debug(logger).Log("func", "InfoDepth", "msg", fmt.Sprint(args...))
}
func Infoln(args ...interface{}) {
level.Debug(logger).Log("func", "Infoln", "msg", fmt.Sprint(args...))
}
func Infof(format string, args ...interface{}) {
level.Debug(logger).Log("func", "Infof", "msg", fmt.Sprintf(format, args...))
}
func Warning(args ...interface{}) {
level.Warn(logger).Log("func", "Warning", "msg", fmt.Sprint(args...))
}
func WarningDepth(depth int, args ...interface{}) {
level.Warn(logger).Log("func", "WarningDepth", "msg", fmt.Sprint(args...))
}
func Warningln(args ...interface{}) {
level.Warn(logger).Log("func", "Warningln", "msg", fmt.Sprint(args...))
}
func Warningf(format string, args ...interface{}) {
level.Warn(logger).Log("func", "Warningf", "msg", fmt.Sprintf(format, args...))
}
func Error(args ...interface{}) {
level.Error(logger).Log("func", "Error", "msg", fmt.Sprint(args...))
}
func ErrorDepth(depth int, args ...interface{}) {
level.Error(logger).Log("func", "ErrorDepth", "msg", fmt.Sprint(args...))
}
func Errorln(args ...interface{}) {
level.Error(logger).Log("func", "Errorln", "msg", fmt.Sprint(args...))
}
func Errorf(format string, args ...interface{}) {
level.Error(logger).Log("func", "Errorf", "msg", fmt.Sprintf(format, args...))
}
func Fatal(args ...interface{}) {
level.Error(logger).Log("func", "Fatal", "msg", fmt.Sprint(args...))
os.Exit(255)
}
func FatalDepth(depth int, args ...interface{}) {
level.Error(logger).Log("func", "FatalDepth", "msg", fmt.Sprint(args...))
os.Exit(255)
}
func Fatalln(args ...interface{}) {
level.Error(logger).Log("func", "Fatalln", "msg", fmt.Sprint(args...))
os.Exit(255)
}
func Fatalf(format string, args ...interface{}) {
level.Error(logger).Log("func", "Fatalf", "msg", fmt.Sprintf(format, args...))
os.Exit(255)
}
func Exit(args ...interface{}) {
level.Error(logger).Log("func", "Exit", "msg", fmt.Sprint(args...))
os.Exit(1)
}
func ExitDepth(depth int, args ...interface{}) {
level.Error(logger).Log("func", "ExitDepth", "msg", fmt.Sprint(args...))
os.Exit(1)
}
func Exitln(args ...interface{}) {
level.Error(logger).Log("func", "Exitln", "msg", fmt.Sprint(args...))
os.Exit(1)
}
func Exitf(format string, args ...interface{}) {
level.Error(logger).Log("func", "Exitf", "msg", fmt.Sprintf(format, args...))
os.Exit(1)
}
func Flush() {}