...
1 package logrus
2
3 import "time"
4
5
6 const (
7 defaultTimestampFormat = time.RFC3339
8 FieldKeyMsg = "msg"
9 FieldKeyLevel = "level"
10 FieldKeyTime = "time"
11 FieldKeyLogrusError = "logrus_error"
12 FieldKeyFunc = "func"
13 FieldKeyFile = "file"
14 )
15
16
17
18
19
20
21
22
23
24
25
26 type Formatter interface {
27 Format(*Entry) ([]byte, error)
28 }
29
30
31
32
33
34
35
36
37
38
39
40
41
42 func prefixFieldClashes(data Fields, fieldMap FieldMap, reportCaller bool) {
43 timeKey := fieldMap.resolve(FieldKeyTime)
44 if t, ok := data[timeKey]; ok {
45 data["fields."+timeKey] = t
46 delete(data, timeKey)
47 }
48
49 msgKey := fieldMap.resolve(FieldKeyMsg)
50 if m, ok := data[msgKey]; ok {
51 data["fields."+msgKey] = m
52 delete(data, msgKey)
53 }
54
55 levelKey := fieldMap.resolve(FieldKeyLevel)
56 if l, ok := data[levelKey]; ok {
57 data["fields."+levelKey] = l
58 delete(data, levelKey)
59 }
60
61 logrusErrKey := fieldMap.resolve(FieldKeyLogrusError)
62 if l, ok := data[logrusErrKey]; ok {
63 data["fields."+logrusErrKey] = l
64 delete(data, logrusErrKey)
65 }
66
67
68 if reportCaller {
69 funcKey := fieldMap.resolve(FieldKeyFunc)
70 if l, ok := data[funcKey]; ok {
71 data["fields."+funcKey] = l
72 }
73 fileKey := fieldMap.resolve(FieldKeyFile)
74 if l, ok := data[fileKey]; ok {
75 data["fields."+fileKey] = l
76 }
77 }
78 }
79
View as plain text