-
Notifications
You must be signed in to change notification settings - Fork 13
/
log.go
178 lines (151 loc) · 3.43 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
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
package log
import (
"fmt"
"os"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/sirupsen/logrus"
)
const (
debugSelector = "apic-agents"
traceSelector = "apic-agents-trace"
)
// Get returns the global logger
func Get() *logrus.Logger {
return log
}
var networkTraceIgnoreHeaders = map[string]interface{}{
"X-Axway-Tenant-Id": true,
"Authorization": true,
}
var isLogP bool
var logHTTPTrace bool
func init() {
networkTrace := os.Getenv("LOG_HTTP_TRACE")
logHTTPTrace = networkTrace == "true"
}
// SetIsLogP -
func SetIsLogP() {
isLogP = true
}
// UnsetIsLogP -
func UnsetIsLogP() {
isLogP = false
}
// Trace -
func Trace(args ...interface{}) {
if isLogP {
// forward trace logs to logp debug with the trace selector
if log.Level == logrus.TraceLevel {
logp.Debug(traceSelector, fmt.Sprint(args...))
}
} else {
log.Trace(args...)
}
}
// Tracef -
func Tracef(format string, args ...interface{}) {
if isLogP {
// forward trace logs to logp debug with the trace selector
if log.Level == logrus.TraceLevel {
logp.Debug(traceSelector, format, args...)
}
} else {
log.Tracef(format, args...)
}
}
// Error -
func Error(args ...interface{}) {
if isLogP {
logp.Err(fmt.Sprint(args...))
} else {
log.Error(args...)
}
}
// Errorf -
func Errorf(format string, args ...interface{}) {
if isLogP {
logp.Err(format, args...)
} else {
log.Errorf(format, args...)
}
}
// Debug -
func Debug(args ...interface{}) {
if isLogP {
logp.Debug(debugSelector, fmt.Sprint(args...))
} else {
log.Debug(args...)
}
}
// Debugf -
func Debugf(format string, args ...interface{}) {
if isLogP {
logp.Debug(debugSelector, format, args...)
} else {
log.Debugf(format, args...)
}
}
// Info -
func Info(args ...interface{}) {
if isLogP {
logp.Info(fmt.Sprint(args...))
} else {
log.Info(args...)
}
}
// Infof -
func Infof(format string, args ...interface{}) {
if isLogP {
logp.Info(format, args...)
} else {
log.Infof(format, args...)
}
}
// Warn -
func Warn(args ...interface{}) {
if isLogP {
logp.Warn(fmt.Sprint(args...))
} else {
log.Warn(args...)
}
}
// Warnf -
func Warnf(format string, args ...interface{}) {
if isLogP {
logp.Warn(format, args...)
} else {
log.Warnf(format, args...)
}
}
// TraceRedacted Redacted log for traces
func TraceRedacted(redactedFields []string, args ...interface{}) {
Trace(ObscureArguments(redactedFields, args...))
}
// ErrorRedacted Redacted log for errors
func ErrorRedacted(redactedFields []string, args ...interface{}) {
Error(ObscureArguments(redactedFields, args...))
}
// InfoRedacted Redacted log for information
func InfoRedacted(redactedFields []string, args ...interface{}) {
Info(ObscureArguments(redactedFields, args...))
}
// DebugRedacted Redacted log for debugging
func DebugRedacted(redactedFields []string, args ...interface{}) {
Debug(ObscureArguments(redactedFields, args...))
}
// SetLevel -
func SetLevel(level logrus.Level) {
log.SetLevel(level)
}
// GetLevel -
func GetLevel() logrus.Level {
return log.GetLevel()
}
// DeprecationWarningReplace - log a deprecation warning with the old and replaced usage
func DeprecationWarningReplace(old string, new string) {
Warnf("%s is deprecated, please start using %s", old, new)
}
// DeprecationWarningDoc - log a deprecation warning with the old and replaced usage
func DeprecationWarningDoc(old string, docRef string) {
Warnf("%s is deprecated, please refer to docs.axway.com regarding %s", old, docRef)
}