This repository has been archived by the owner on Jan 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_logging.go
201 lines (187 loc) · 3.56 KB
/
server_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package commandamqp
import (
"context"
"github.com/jmalloc/twelf/src/twelf"
"github.com/rinq/rinq-go/src/rinq"
"github.com/rinq/rinq-go/src/rinq/ident"
"github.com/rinq/rinq-go/src/rinq/trace"
)
func logServerInvalidMessageID(
logger twelf.Logger,
peerID ident.PeerID,
msgID string,
) {
logger.Debug(
"%s server ignored AMQP message, '%s' is not a valid message ID",
peerID.ShortString(),
msgID,
)
}
func logIgnoredMessage(
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
err error,
) {
logger.Debug(
"%s server ignored AMQP message %s, %s",
peerID.ShortString(),
msgID.ShortString(),
err,
)
}
func logRequestBegin(
ctx context.Context,
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
req rinq.Request,
) {
logger.Debug(
"%s server began '%s::%s' command request %s [%s] <<< %s",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
trace.Get(ctx),
req.Payload,
)
}
func logRequestEnd(
ctx context.Context,
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
req rinq.Request,
payload *rinq.Payload,
err error,
) {
if !logger.IsDebug() {
return
}
switch e := err.(type) {
case nil:
logger.Debug(
"%s server completed '%s::%s' command request %s successfully [%s] >>> %s",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
trace.Get(ctx),
payload,
)
case rinq.Failure:
var message string
if e.Message != "" {
message = ": " + e.Message
}
logger.Debug(
"%s server completed '%s::%s' command request %s with '%s' failure%s [%s] <<< %s",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
e.Type,
message,
trace.Get(ctx),
payload,
)
default:
logger.Debug(
"%s server completed '%s::%s' command request %s with error [%s] <<< %s",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
trace.Get(ctx),
err,
)
}
}
func logNoLongerListening(
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
ns string,
) {
logger.Debug(
"%s is no longer listening to '%s' namespace, request %s has been re-queued",
peerID.ShortString(),
ns,
msgID.ShortString(),
)
}
func logRequestRequeued(
ctx context.Context,
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
req rinq.Request,
) {
logger.Debug(
"%s did not write a response for '%s::%s' command request, request %s has been re-queued [%s]",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
trace.Get(ctx),
)
}
func logRequestRejected(
ctx context.Context,
logger twelf.Logger,
peerID ident.PeerID,
msgID ident.MessageID,
req rinq.Request,
reason string,
) {
logger.Log(
"%s did not write a response for '%s::%s' command request %s, request has been abandoned (%s) [%s]",
peerID.ShortString(),
req.Namespace,
req.Command,
msgID.ShortString(),
reason,
trace.Get(ctx),
)
}
func logServerStart(
logger twelf.Logger,
peerID ident.PeerID,
preFetch uint,
) {
logger.Debug(
"%s server started with (pre-fetch: %d)",
peerID.ShortString(),
preFetch,
)
}
func logServerStopping(
logger twelf.Logger,
peerID ident.PeerID,
pending uint,
) {
logger.Debug(
"%s server is stopping gracefully (pending: %d)",
peerID.ShortString(),
pending,
)
}
func logServerStop(
logger twelf.Logger,
peerID ident.PeerID,
err error,
) {
if err == nil {
logger.Debug(
"%s server stopped",
peerID.ShortString(),
)
} else {
logger.Debug(
"%s server stopped: %s",
peerID.ShortString(),
err,
)
}
}