-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexported.go
More file actions
74 lines (64 loc) · 2.87 KB
/
Copy pathexported.go
File metadata and controls
74 lines (64 loc) · 2.87 KB
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
package logger
import (
"strconv"
"time"
)
// WithField creates an entry from the standard logger and adds a field to
// it. If you want multiple fields, use `WithFields`.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func (ulog *UPPLogger) WithField(key string, value interface{}) *LogEntry {
return &LogEntry{ulog, ulog.Logger.WithField(key, value)}
}
// WithFields creates an entry from the standard logger and adds multiple
// fields to it. This is simply a helper for `WithField`, invoking it
// once for each field.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func (ulog *UPPLogger) WithFields(fields map[string]interface{}) *LogEntry {
return &LogEntry{ulog, ulog.Logger.WithFields(fields)}
}
// WithTransactionID creates an entry from the standard logger and adds transaction_id field to it.
func (ulog *UPPLogger) WithTransactionID(tid string) *LogEntry {
return ulog.WithField(ulog.keyConf.KeyTransactionID, tid)
}
// WithError creates an entry from the standard logger and adds an error field to it.
func (ulog *UPPLogger) WithError(err error) *LogEntry {
return ulog.WithField(ulog.keyConf.KeyError, err)
}
// WithUUID creates an entry from the standard logger and adds an uuid field to it.
func (ulog *UPPLogger) WithUUID(uuid string) *LogEntry {
return ulog.WithField(ulog.keyConf.KeyUUID, uuid)
}
// WithValidFlag creates an entry from the standard logger and adds an "is valid" field to it.
func (ulog *UPPLogger) WithValidFlag(isValid bool) *LogEntry {
return ulog.WithField(ulog.keyConf.KeyIsValid, strconv.FormatBool(isValid))
}
// WithTime creates an entry from the standard logger and adds an time field to it.
func (ulog *UPPLogger) WithTime(time time.Time) *LogEntry {
return ulog.WithField(ulog.keyConf.KeyTime, time.Format(timestampFormat))
}
// WithMonitoringEvent creates an entry from the standard logger and adds monitoring event fields to it.
// The monitoring event fields are "monitoring_event", "event" and "content_type".
func (ulog *UPPLogger) WithMonitoringEvent(eventName, tid, contentType string) *LogEntry {
e := ulog.WithFields(
map[string]interface{}{
ulog.keyConf.KeyMonitoringEvent: "true",
ulog.keyConf.KeyEventName: eventName,
ulog.keyConf.KeyContentType: contentType,
})
return e.WithTransactionID(tid)
}
// WithCategorisedEvent creates an entry from the standard logger and adds categorised event fields to it.
// The added fields are "event", "event_category" and "event_msg".
func (ulog *UPPLogger) WithCategorisedEvent(eventName, eventCategory, eventMsg, tid string) *LogEntry {
e := ulog.WithFields(
map[string]interface{}{
ulog.keyConf.KeyEventName: eventName,
ulog.keyConf.KeyEventCategory: eventCategory,
ulog.keyConf.KeyEventMsg: eventMsg,
})
return e.WithTransactionID(tid)
}