Skip to content

Commit 3839b3a

Browse files
authored
Merge pull request #137 from snabble/add-type-deprecation
Add `"type": "deprecation"`
2 parents caf5c0f + b72e7c2 commit 3839b3a

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

helper.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func createAccessEntry(r *http.Request, start time.Time, statusCode int, err err
122122
url += "?" + r.URL.RawQuery
123123
}
124124
fields := logrus.Fields{
125-
"type": "access",
125+
TypeField: TypeAccess,
126126
"@timestamp": start,
127127
"remote_ip": getRemoteIP(r),
128128
"host": r.Host,
@@ -163,7 +163,7 @@ func Call(r *http.Request, resp *http.Response, start time.Time, err error) {
163163
// FlakyCall logs the result of an outgoing call and marks it as flaky
164164
func FlakyCall(r *http.Request, resp *http.Response, start time.Time, err error) {
165165
fields := fieldsForCall(r, resp, start, err)
166-
fields["flaky"] = true
166+
fields[FlakyField] = true
167167
logCall(fields, r, resp, err)
168168
}
169169

@@ -173,7 +173,7 @@ func fieldsForCall(r *http.Request, resp *http.Response, start time.Time, err er
173173
url += "?" + r.URL.RawQuery
174174
}
175175
fields := logrus.Fields{
176-
"type": "call",
176+
TypeField: TypeCall,
177177
"@timestamp": start,
178178
"host": r.Host,
179179
"url": url,
@@ -233,17 +233,17 @@ func Cacheinfo(url string, hit bool) {
233233
}
234234
Log.WithFields(
235235
logrus.Fields{
236-
"type": "cacheinfo",
237-
"url": url,
238-
"hit": hit,
236+
TypeField: TypeCacheinfo,
237+
"url": url,
238+
"hit": hit,
239239
}).
240240
Debug(msg)
241241
}
242242

243243
// Application Return a log entry for application logs.
244244
func Application(h http.Header) *Entry {
245245
fields := logrus.Fields{
246-
"type": "application",
246+
TypeField: TypeApplication,
247247
}
248248
return Log.WithFields(fields)
249249
}
@@ -263,7 +263,7 @@ func LifecycleStart(appName string, args interface{}) {
263263
}
264264
}
265265

266-
fields["type"] = "lifecycle"
266+
fields[TypeField] = TypeLifecycle
267267
fields["event"] = "start"
268268
for _, env := range LifecycleEnvVars {
269269
if os.Getenv(env) != "" {
@@ -277,8 +277,8 @@ func LifecycleStart(appName string, args interface{}) {
277277
// LifecycleStop logs the request to stop an application
278278
func LifecycleStop(appName string, signal os.Signal, err error) {
279279
fields := logrus.Fields{
280-
"type": "lifecycle",
281-
"event": "stop",
280+
TypeField: TypeLifecycle,
281+
"event": "stop",
282282
}
283283
if signal != nil {
284284
fields["signal"] = signal.String()
@@ -310,8 +310,8 @@ func LifecycleStopped(appName string, err error) {
310310

311311
func logApplicationLifecycleEvent(appName string, eventName string, err error) {
312312
fields := logrus.Fields{
313-
"type": "lifecycle",
314-
"event": eventName,
313+
TypeField: TypeLifecycle,
314+
"event": eventName,
315315
}
316316

317317
if os.Getenv("BUILD_NUMBER") != "" {
@@ -330,8 +330,8 @@ func logApplicationLifecycleEvent(appName string, eventName string, err error) {
330330
// ServerClosed logs the closing of a server
331331
func ServerClosed(appName string) {
332332
fields := logrus.Fields{
333-
"type": "application",
334-
"event": "stop",
333+
TypeField: TypeApplication,
334+
"event": "stop",
335335
}
336336

337337
if os.Getenv("BUILD_NUMBER") != "" {

logger.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const (
1616
OrderField = "order"
1717
CheckoutDeviceField = "checkoutDevice"
1818
DurationField = "duration"
19+
FlakyField = "flaky"
20+
TypeField = "type"
21+
22+
TypeDeprecation = "deprecation"
23+
TypeCall = "call"
24+
TypeAccess = "access"
25+
TypeApplication = "application"
26+
TypeLifecycle = "lifecycle"
27+
TypeCacheinfo = "cacheinfo"
1928
)
2029

2130
type Identifiable interface {
@@ -146,6 +155,13 @@ func (entry *Entry) WithOrder(orderID string) *Entry {
146155
return entry.WithField(OrderField, orderID)
147156
}
148157

158+
// Deprecation marks the log entry with type "deprecation". This is used for log entries, that are logged during a
159+
// feature change. Logs with "deprecation" types should not be considered as critical and should only occur temporarily
160+
// during the transition.
161+
func (entry *Entry) Deprecation() *Entry {
162+
return entry.WithField(TypeField, TypeDeprecation)
163+
}
164+
149165
func wrapEntry(logrusEntry *logrus.Entry) *Entry {
150166
return &Entry{Entry: logrusEntry}
151167
}

0 commit comments

Comments
 (0)