-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.go
More file actions
77 lines (65 loc) · 3.12 KB
/
Copy pathentry.go
File metadata and controls
77 lines (65 loc) · 3.12 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
75
76
77
package logger
import (
"strconv"
"time"
"github.com/sirupsen/logrus"
)
// LogEntry is wrapper around logrus.Entry with a few methods adding UPP specific keys to the log entries.
// LogEntry is the final or intermediate logging entry. It's finally logged when Debug, Info,
// Warn, Error, Fatal or Panic is called on it.
type LogEntry struct {
ulog *UPPLogger
*logrus.Entry
}
// WithField for LogEntry is wrapper around WithField of logrus.Entry
// that let us return our object when chaining the calls to WithField.
func (entry *LogEntry) WithField(key string, value interface{}) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(key, value)}
}
// WithFields for LogEntry is wrapper around WithFields of logrus.Entry
// that let us return our object when chaining the calls to WithFields.
func (entry *LogEntry) WithFields(fields map[string]interface{}) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithFields(fields)}
}
// WithUUID returns new LogEntry with uuid field in it.
func (entry *LogEntry) WithUUID(uuid string) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(entry.ulog.keyConf.KeyUUID, uuid)}
}
// WithValidFlag returns new LogEntry with "is valid" field in it.
func (entry *LogEntry) WithValidFlag(isValid bool) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(entry.ulog.keyConf.KeyIsValid, strconv.FormatBool(isValid))}
}
// WithTime returns new LogEntry with time field in it.
func (entry *LogEntry) WithTime(time time.Time) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(entry.ulog.keyConf.KeyTime, time.Format(timestampFormat))}
}
// WithTransactionID returns new LogEntry with transaction id field in it.
func (entry *LogEntry) WithTransactionID(tid string) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(entry.ulog.keyConf.KeyTransactionID, tid)}
}
// WithError returns new LogEntry with error field in it.
func (entry *LogEntry) WithError(err error) *LogEntry {
return &LogEntry{ulog: entry.ulog, Entry: entry.Entry.WithField(entry.ulog.keyConf.KeyError, err)}
}
// WithMonitoringEvent returns new LogEntry with monitoring event fields in it.
// The monitoring event fields are boolean valued monitoring event, event name and content type.
func (entry *LogEntry) WithMonitoringEvent(eventName, tid, contentType string) *LogEntry {
e := entry.WithFields(
map[string]interface{}{
entry.ulog.keyConf.KeyMonitoringEvent: "true",
entry.ulog.keyConf.KeyEventName: eventName,
entry.ulog.keyConf.KeyContentType: contentType,
})
return e.WithTransactionID(tid)
}
// WithCategorisedEvent returns new LogEntry with categorised event fields in it.
// The categorised event fields are event name, event category, event message.
func (entry *LogEntry) WithCategorisedEvent(eventName, eventCategory, eventMsg, tid string) *LogEntry {
e := entry.WithFields(
map[string]interface{}{
entry.ulog.keyConf.KeyEventName: eventName,
entry.ulog.keyConf.KeyEventCategory: eventCategory,
entry.ulog.keyConf.KeyEventMsg: eventMsg,
})
return e.WithTransactionID(tid)
}