/
bolt_logging.go
93 lines (78 loc) · 2.1 KB
/
bolt_logging.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
package bolt
import (
"encoding/json"
"github.com/neo4j/neo4j-go-driver/v4/neo4j/db"
"strconv"
"strings"
)
type loggableDictionary map[string]interface{}
func (d loggableDictionary) String() string {
if credentials, ok := d["credentials"]; ok {
d["credentials"] = "<redacted>"
defer func() {
d["credentials"] = credentials
}()
}
return serializeTrace(d)
}
type loggableStringDictionary map[string]string
func (sd loggableStringDictionary) String() string {
if credentials, ok := sd["credentials"]; ok {
sd["credentials"] = "<redacted>"
defer func() {
sd["credentials"] = credentials
}()
}
return serializeTrace(sd)
}
type loggableList []interface{}
func (l loggableList) String() string {
return serializeTrace(l)
}
type loggableStringList []string
func (s loggableStringList) String() string {
return serializeTrace(s)
}
type loggableSuccess success
type loggedSuccess struct {
Server string `json:"server,omitempty"`
ConnectionId string `json:"connection_id,omitempty"`
Fields []string `json:"fields,omitempty"`
TFirst string `json:"t_first,omitempty"`
Bookmark string `json:"bookmark,omitempty"`
TLast string `json:"t_last,omitempty"`
HasMore bool `json:"has_more,omitempy"`
Db string `json:"db,omitempty"`
}
func (s loggableSuccess) String() string {
return serializeTrace(loggedSuccess{
Server: s.server,
ConnectionId: s.connectionId,
Fields: s.fields,
TFirst: formatOmittingZero(s.tfirst),
Bookmark: s.bookmark,
TLast: formatOmittingZero(s.tlast),
HasMore: s.hasMore,
Db: s.db,
})
}
func formatOmittingZero(i int64) string {
if i == 0 {
return ""
}
return strconv.FormatInt(i, 10)
}
type loggableFailure db.Neo4jError
func (f loggableFailure) String() string {
return serializeTrace(map[string]interface{}{
"code": f.Code,
"message": f.Msg,
})
}
func serializeTrace(v interface{}) string {
builder := strings.Builder{}
encoder := json.NewEncoder(&builder)
encoder.SetEscapeHTML(false)
_ = encoder.Encode(v)
return strings.TrimSpace(builder.String())
}