-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathglog.go
173 lines (143 loc) · 3.65 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package glog exposes an API subset of the [glog](https://github.com/golang/glog) package.
// All logging state delivered to this package is shunted to the global [zap logger](https://github.com/uber-go/zap).
//
// Istio is built on top of zap logger. We depend on some downstream components that use glog for logging.
// This package makes it so we can intercept the calls to glog and redirect them to zap and thus produce
// a consistent log for our processes.
package glog
import (
"fmt"
"os"
"go.uber.org/zap"
)
// Level is a shim
type Level int32
// Verbose is a shim
type Verbose bool
// Flush is a shim
func Flush() {
zap.L().Sync()
}
// V is a shim
func V(level Level) Verbose {
return Verbose(zap.L().Core().Enabled(zap.DebugLevel))
}
// Info is a shim
func (v Verbose) Info(args ...interface{}) {
zap.S().Debug(args...)
}
// Infoln is a shim
func (v Verbose) Infoln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Debug(s, "\n")
}
// Infof is a shim
func (v Verbose) Infof(format string, args ...interface{}) {
zap.S().Debugf(format, args...)
}
// Info is a shim
func Info(args ...interface{}) {
zap.S().Info(args...)
}
// InfoDepth is a shim
func InfoDepth(depth int, args ...interface{}) {
zap.S().Info(args...)
}
// Infoln is a shim
func Infoln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Info(s, "\n")
}
// Infof is a shim
func Infof(format string, args ...interface{}) {
zap.S().Infof(format, args...)
}
// Warning is a shim
func Warning(args ...interface{}) {
zap.S().Warn(args...)
}
// WarningDepth is a shim
func WarningDepth(depth int, args ...interface{}) {
zap.S().Warn(args...)
}
// Warningln is a shim
func Warningln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Warn(s, "\n")
}
// Warningf is a shim
func Warningf(format string, args ...interface{}) {
zap.S().Warnf(format, args...)
}
// Error is a shim
func Error(args ...interface{}) {
zap.S().Error(args...)
}
// ErrorDepth is a shim
func ErrorDepth(depth int, args ...interface{}) {
zap.S().Error(args...)
}
// Errorln is a shim
func Errorln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Error(s, "\n")
}
// Errorf is a shim
func Errorf(format string, args ...interface{}) {
zap.S().Errorf(format, args...)
}
// Fatal is a shim
func Fatal(args ...interface{}) {
zap.S().Error(args...)
os.Exit(255)
}
// FatalDepth is a shim
func FatalDepth(depth int, args ...interface{}) {
zap.S().Error(args...)
os.Exit(255)
}
// Fatalln is a shim
func Fatalln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Error(s, "\n")
os.Exit(255)
}
// Fatalf is a shim
func Fatalf(format string, args ...interface{}) {
zap.S().Errorf(format, args...)
os.Exit(255)
}
// Exit is a shim
func Exit(args ...interface{}) {
zap.S().Error(args...)
os.Exit(1)
}
// ExitDepth is a shim
func ExitDepth(depth int, args ...interface{}) {
zap.S().Error(args...)
os.Exit(1)
}
// Exitln is a shim
func Exitln(args ...interface{}) {
s := fmt.Sprint(args)
zap.S().Error(s, "\n")
os.Exit(1)
}
// Exitf is a shim
func Exitf(format string, args ...interface{}) {
zap.S().Errorf(format, args...)
os.Exit(1)
}