This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.funcs.go
185 lines (159 loc) · 4.81 KB
/
logger.funcs.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
174
175
176
177
178
179
180
181
182
183
184
185
//go:build !veryquiet
// +build !veryquiet
package log
import "fmt"
// VeryQuietEnabled identify whether `--tags=veryquiet` has been defined in go building
var VeryQuietEnabled = false
// Tracef prints the text to stdin if logging level is greater than TraceLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Tracef(msg string, args ...interface{}) {
logger.Tracef(msg, args...)
}
// Debugf prints the text to stdin if logging level is greater than DebugLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Debugf(msg string, args ...interface{}) {
logger.Debugf(msg, args...)
}
// Infof prints the text to stdin if logging level is greater than InfoLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Infof(msg string, args ...interface{}) {
logger.Infof(msg, args...)
}
// Warnf prints the text to stderr
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Warnf(msg string, args ...interface{}) {
logger.Warnf(msg, args...)
}
// Errorf prints the text to stderr
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Errorf(msg string, args ...interface{}) {
logger.Errorf(msg, args...)
}
// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Fatalf(msg string, args ...interface{}) {
if InTesting() {
logger.Panicf(msg, args...)
}
logger.Fatalf(msg, args...)
}
// Panicf is equivalent to Printf() followed by a call to panic().
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Panicf(msg string, args ...interface{}) {
logger.Panicf(msg, args...)
}
// Printf calls Output to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Printf(msg string, args ...interface{}) {
logger.Printf(msg, args...)
}
// Trace prints all args to stdin if logging level is greater than TraceLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Trace(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Trace(args...)
}
}
// Debug prints all args to stdin if logging level is greater than DebugLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Debug(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Debug(args...)
}
}
// Info prints all args to stdin if logging level is greater than InfoLevel
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Info(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Info(args...)
}
}
// Warn prints all args to stderr
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Warn(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Warn(args...)
}
}
// Error prints all args to stderr
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Error(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Error(args...)
}
}
// Fatal is equivalent to Printf() followed by a call to os.Exit(1).
// It would be optimized to discard if `--tags=veryquiet` was been defined.
//
// If all args are nil, Fatal will return to caller normally.
func Fatal(args ...interface{}) {
if l := AsL(logger); l != nil {
var has bool
var cnt int
var ent interface{}
for _, e := range args {
if e != nil {
has, ent = true, e
cnt++
}
}
if !has {
return
}
if cnt == 1 {
str := fmt.Sprintf("Error occurred: %+v", ent)
if InTesting() {
l.Panic(str)
} else {
l.Fatal(str)
}
return
}
if InTesting() {
l.Panic(args...)
}
l.Fatal(args...)
}
}
// Panic is equivalent to Printf() followed by a call to panic().
// It would be optimized to discard if `--tags=veryquiet` was been defined.
//
// If all args are nil, Panic will return to caller normally.
func Panic(args ...interface{}) {
if l := AsL(logger); l != nil {
var has bool
var cnt int
var ent interface{}
for _, e := range args {
if e != nil {
has, ent = true, e
cnt++
}
}
if !has {
return
}
if cnt == 1 {
l.Panic("Error occurred: %+v", ent)
return
}
l.Panic(args...)
}
}
// Print calls Output to print to the standard logger.
// Arguments are handled in the manner of fmt.Print.
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Print(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Print(args...)
}
}
// Println calls Output to print to the standard logger.
// Arguments are handled in the manner of fmt.Println.
// It would be optimized to discard if `--tags=veryquiet` was been defined.
func Println(args ...interface{}) {
if l := AsL(logger); l != nil {
l.Println(args...)
}
}