-
Notifications
You must be signed in to change notification settings - Fork 18
/
fields.go
363 lines (295 loc) · 10.5 KB
/
fields.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package logging
import (
"encoding/hex"
"fmt"
"time"
ptypes "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/zap"
)
func Hash(h []byte) zap.Field {
hs := hex.EncodeToString(h)
return zap.String("hash", hs)
}
// Binary constructs a field that carries an opaque binary blob.
//
// Binary data is serialized in an encoding-appropriate format. For example,
// zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text,
// use ByteString.
func Binary(key string, val []byte) zap.Field {
return zap.Binary(key, val)
}
// Bool constructs a field that carries a bool.
func Bool(key string, val bool) zap.Field {
return zap.Bool(key, val)
}
// ByteString constructs a field that carries UTF-8 encoded text as a []byte.
// To log opaque binary blobs (which aren't necessarily valid UTF-8), use
// Binary.
func ByteString(key string, val []byte) zap.Field {
return zap.ByteString(key, val)
}
// Complex128 constructs a field that carries a complex number. Unlike most
// numeric fields, this costs an allocation (to convert the complex128 to
// interface{}).
func Complex128(key string, val complex128) zap.Field {
return zap.Complex128(key, val)
}
// Complex64 constructs a field that carries a complex number. Unlike most
// numeric fields, this costs an allocation (to convert the complex64 to
// interface{}).
func Complex64(key string, val complex64) zap.Field {
return zap.Complex64(key, val)
}
// Float64 constructs a field that carries a float64. The way the
// floating-point value is represented is encoder-dependent, so marshaling is
// necessarily lazy.
func Float64(key string, val float64) zap.Field {
return zap.Float64(key, val)
}
// Float32 constructs a field that carries a float32. The way the
// floating-point value is represented is encoder-dependent, so marshaling is
// necessarily lazy.
func Float32(key string, val float32) zap.Field {
return zap.Float32(key, val)
}
// Int constructs a field with the given key and value.
func Int(key string, val int) zap.Field {
return Int64(key, int64(val))
}
// Int64 constructs a field with the given key and value.
func Int64(key string, val int64) zap.Field {
return zap.Int64(key, val)
}
// Int32 constructs a field with the given key and value.
func Int32(key string, val int32) zap.Field {
return zap.Int32(key, val)
}
// Int16 constructs a field with the given key and value.
func Int16(key string, val int16) zap.Field {
return zap.Int16(key, val)
}
// Int8 constructs a field with the given key and value.
func Int8(key string, val int8) zap.Field {
return zap.Int8(key, val)
}
// String constructs a field with the given key and value.
func String(key string, val string) zap.Field {
return zap.String(key, val)
}
// Strings constructs a field with the given key and value.
func Strings(key string, val []string) zap.Field {
return zap.Strings(key, val)
}
// Decimal constructs a field with the given key and value.
func Decimal(key string, val fmt.Stringer) zap.Field {
return String(key, val.String())
}
// BigUint constructs a field with the given key and value.
func BigUint(key string, val fmt.Stringer) zap.Field {
return String(key, val.String())
}
// BigInt constructs a field with the given key and value.
func BigInt(key string, val fmt.Stringer) zap.Field {
return String(key, val.String())
}
func EthereumAddresses(addresses []common.Address) zap.Field {
strings := []string{}
for _, v := range addresses {
strings = append(strings, v.String())
}
return Strings("addresses", strings)
}
// Uint constructs a field with the given key and value.
func Uint(key string, val uint) zap.Field {
return Uint64(key, uint64(val))
}
// Uint64 constructs a field with the given key and value.
func Uint64(key string, val uint64) zap.Field {
return zap.Uint64(key, val)
}
// Uint32 constructs a field with the given key and value.
func Uint32(key string, val uint32) zap.Field {
return zap.Uint32(key, val)
}
// Uint16 constructs a field with the given key and value.
func Uint16(key string, val uint16) zap.Field {
return zap.Uint16(key, val)
}
// Uint8 constructs a field with the given key and value.
func Uint8(key string, val uint8) zap.Field {
return zap.Uint8(key, val)
}
// Uintptr constructs a field with the given key and value.
func Uintptr(key string, val uintptr) zap.Field {
return zap.Uintptr(key, val)
}
func Duration(key string, value time.Duration) zap.Field {
return zap.String(key, value.String())
}
// Error constructs a field with the given error value.
func Error(val error) zap.Field {
return zap.Error(val)
}
// Candle constructs a field with the given VEGA candle proto value.
func Candle(c fmt.Stringer) zap.Field {
return zap.String("candle", c.String())
}
// CandleWithTag constructs a field with the given VEGA candle proto value and key equal to the tag string.
func CandleWithTag(c fmt.Stringer, tag string) zap.Field {
return zap.String(tag, c.String())
}
// Order constructs a field with the given VEGA order value.
func Order(o fmt.Stringer) zap.Field {
return zap.String("order", o.String())
}
// ProtoOrder constructs a field with the given VEGA order proto value.
func ProtoOrder(o ptypes.Order) zap.Field {
return zap.String("order", o.String())
}
func OrderID(id string) zap.Field {
return zap.String("order-id", id)
}
// Time display a time.
func Time(key string, t time.Time) zap.Field {
return zap.Time(key, t)
}
// OrderWithTag constructs a field with the given VEGA order proto value and key equal to the tag string.
func OrderWithTag(o fmt.Stringer, tag string) zap.Field {
return zap.String(tag, o.String())
}
// Trade constructs a field with the given VEGA trade proto value.
func Trade(t fmt.Stringer) zap.Field {
return zap.String("trade", t.String())
}
// Market constructs a field with the given VEGA market proto value.
func Market(m fmt.Stringer) zap.Field {
return zap.String("market", m.String())
}
func MarketID(id string) zap.Field {
return zap.String("market-id", id)
}
func AssetID(id string) zap.Field {
return zap.String("asset-id", id)
}
func WithdrawalID(id string) zap.Field {
return zap.String("withdrawal-id", id)
}
func LiquidityID(id string) zap.Field {
return zap.String("liquidity-id", id)
}
func LiquidityProvisionSubmissionProto(
lp *commandspb.LiquidityProvisionSubmission,
) zap.Field {
return zap.String("liquidity-provision-submission", lp.String())
}
func LiquidityProvisionSubmission(
lp fmt.Stringer,
) zap.Field {
return zap.String("liquidity-provision-submission", lp.String())
}
func LiquidityProvisionCancellationProto(
lp *commandspb.LiquidityProvisionCancellation,
) zap.Field {
return zap.String("liquidity-provision-cancellation", lp.String())
}
func LiquidityProvisionCancellation(
lp fmt.Stringer,
) zap.Field {
return zap.String("liquidity-provision-cancellation", lp.String())
}
func LiquidityProvisionAmendmentProto(
lp *commandspb.LiquidityProvisionAmendment,
) zap.Field {
return zap.String("liquidity-provision-amendment", lp.String())
}
func LiquidityProvisionAmendment(
lp fmt.Stringer,
) zap.Field {
return zap.String("liquidity-provision-amendment", lp.String())
}
func WithdrawSubmissionProto(
lp *commandspb.WithdrawSubmission,
) zap.Field {
return zap.String("withdraw-submission", lp.String())
}
func WithdrawSubmission(
lp fmt.Stringer,
) zap.Field {
return zap.String("withdraw-submission", lp.String())
}
// Party constructs a field with the given VEGA party proto value.
func Party(p fmt.Stringer) zap.Field {
return zap.String("party", p.String())
}
func PartyID(id string) zap.Field {
return zap.String("party", id)
}
func ProposalID(id string) zap.Field {
return zap.String("proposal-id", id)
}
// Account constructs a field with the given VEGA account proto value.
func Account(a fmt.Stringer) zap.Field {
return zap.String("account", a.String())
}
// ProtoAccount constructs a field with the given VEGA account proto value.
func ProtoAccount(a ptypes.Account) zap.Field {
return zap.String("account", a.String())
}
// OrderAmendmentProto constructs a single string field to contain all the object information.
func OrderAmendmentProto(oa *commandspb.OrderAmendment) zap.Field {
return zap.String("order-amendment", oa.String())
}
// OrderAmendment constructs a single string field to contain all the object information.
func OrderAmendment(oa fmt.Stringer) zap.Field {
return zap.String("order-amendment", oa.String())
}
// OrderSubmissionProto constructs a single string field to contain all the object information.
func OrderSubmissionProto(os *commandspb.OrderSubmission) zap.Field {
return zap.String("order-submission", os.String())
}
// OrderSubmission constructs a single string field to contain all the object information.
func OrderSubmission(os fmt.Stringer) zap.Field {
return zap.String("order-submission", os.String())
}
// StopOrderSubmission constructs a single string field to contain all the object information.
func StopOrderSubmission(os fmt.Stringer) zap.Field {
return zap.String("stop-order-submission", os.String())
}
// StopOrderCanmcellation constructs a single string field to contain all the object information.
func StopOrderCancellation(os fmt.Stringer) zap.Field {
return zap.String("stop-order-cancellation", os.String())
}
func OrderCancellation(oc fmt.Stringer) zap.Field {
return zap.String("order-cancellation", oc.String())
}
// Reflect constructs a field by running reflection over all the
// field of value passed as a parameter.
// This should never be used we basic log level,
// only in the case of Debug log level, and with guards on top
// of the actual log call for this level.
func Reflect(key string, val interface{}) zap.Field {
return zap.Reflect(key, val)
}
type Tracer interface {
TraceID() string
}
// TraceID logs the event traceID.
func TraceID(e Tracer) zap.Field {
return zap.String("trace-id", e.TraceID())
}