-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.go
676 lines (594 loc) · 23.1 KB
/
sub.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
// This file is generated, DO NOT EDIT. It comes from the corresponding .zzzgo file
package xop
import (
"strconv"
"sync/atomic"
"time"
"github.com/xoplog/xop-go/xopat"
"github.com/xoplog/xop-go/xopbase"
"github.com/xoplog/xop-go/xopconst"
"github.com/xoplog/xop-go/xopnum"
)
// Sub holds an ephemeral state of a log being tranformed to a new log.
type Sub struct {
detached bool
settings LogSettings
logger *Logger
}
// Detaching is a ephemeral type used in the chain
//
// child := logger.Sub().Detach().Fork()
// child := logger.Sub().Detach().Step()
//
// to indicate that the new logger/span has an independent lifetime
// from it's parent so a call to Done() on the parent does not imply
// the child is done.
type Detaching struct {
sub *Sub
}
// RedactAnyFunc is used to redact models as they're being logged.
// It is RedactAnyFunc's responsibility to call
//
// baseLine.Any(k, xopbase.ModelArg{
// Model: v,
// })
//
// if it wants the value to be logged. If it does make that call, it
// must pass an immutable value. Perhaps use "github.com/mohae/deepcopy"
// to make a copy?
//
// The provided xopbase.Line may not be retained beyond the duration of
// the function call.
type RedactAnyFunc func(baseLine xopbase.Line, k xopat.K, v interface{}, alreadyImmutable bool)
// RedactStringFunc is used to redact strings as they're being logged.
// It is RedactStringFunc's responsiblity to call
//
// baseLine.String(k, v, xopbase.StringDataType)
//
// if it wants the value to be logged.
//
// RedactStringFunc is applied only to String(), and Stringer() attributes.
// It is not applied to Msg(), Msgf(), or Msgs().
//
// The provided xopbase.Line may not be retained beyond the duration of
// the function call.
type RedactStringFunc func(baseLine xopbase.Line, k xopat.K, v string)
// RedactErrorFunc is used to redact or format errors as they're being
// logged. It is RedactErrorFunc's responsibility to call
//
// baseLine.String(k, v.Error(), xopbase.ErrorDataType)
//
// if it wants the value to be logged. Alternatively, it could log the
// error as a model:
//
// baseLine.Any(k, v)
//
// The provided xopbase.Line may not be retained beyond the duration of
// the function call.
type RedactErrorFunc func(baseLine xopbase.Line, k xopat.K, v error)
type LogSettings struct {
prefillMsg string
prefillData []func(xopbase.Prefilling)
minimumLogLevel xopnum.Level
stackFramesWanted [xopnum.AlertLevel + 1]int // indexed
tagLinesWithSpanSequence bool
synchronousFlushWhenDone bool
redactAny RedactAnyFunc
redactString RedactStringFunc
redactError RedactErrorFunc
stackFilenameRewrite func(string) string
}
// String is for debugging purposes. It is not complete or preformant.
func (settings LogSettings) String() string {
var str string
if settings.prefillMsg != "" {
str += " prefill:" + settings.prefillMsg
}
if len(settings.prefillData) > 0 {
str += " prefillDataCount:" + strconv.Itoa(len(settings.prefillData))
}
if settings.minimumLogLevel != 0 {
str += " minLevel:" + settings.minimumLogLevel.String()
}
if settings.synchronousFlushWhenDone {
str += " flush-when-done"
}
return str
}
// DefaultSettings are the settings that are used if no setting changes
// are made. Trace logs are excluded. Alert and Error level log lines
// get stack traces.
var DefaultSettings = func() LogSettings {
var settings LogSettings
settings.stackFramesWanted[xopnum.AlertLevel] = 20
settings.stackFramesWanted[xopnum.ErrorLevel] = 10
settings.minimumLogLevel = xopnum.DebugLevel
settings.synchronousFlushWhenDone = true
settings.stackFilenameRewrite = func(s string) string { return s }
return settings
}()
func (settings LogSettings) Copy() LogSettings {
if settings.prefillData != nil {
n := make([]func(xopbase.Prefilling), len(settings.prefillData))
copy(n, settings.prefillData)
settings.prefillData = n
}
return settings
}
func (logger *Logger) Settings() LogSettings {
return logger.settings.Copy()
}
// Sub is a first step in creating a sub-Log from the current logger.
// Sub allows log settings to be modified. The returned value must
// be used. It is used by a call to sub.Logger(), sub.Fork(), or
// sub.Step().
//
// Logs created from Sub() are done when their parent is done.
func (logger *Logger) Sub() *Sub {
return &Sub{
settings: logger.settings.Copy(),
logger: logger,
}
}
// Detach followed by Fork() or Step() creates a sub-span/logger that is detached from
// it's parent. A Done() on the parent does not imply Done() on the detached
// logger.
func (sub Sub) Detach() *Detaching {
sub.detached = true
return &Detaching{
sub: &sub,
}
}
func (d *Detaching) Step(msg string, mods ...SeedModifier) *Logger { return d.sub.Step(msg, mods...) }
func (d *Detaching) Fork(msg string, mods ...SeedModifier) *Logger { return d.sub.Fork(msg, mods...) }
// Fork creates a new logger that does not need to be terminated because
// it is assumed to be done with the current logger is finished. The new logger
// has its own span.
func (sub *Sub) Fork(msg string, mods ...SeedModifier) *Logger {
seed := sub.logger.capSpan.SubSeed(mods...)
counter := int(atomic.AddInt32(&sub.logger.span.forkCounter, 1))
seed.spanSequenceCode += "." + base26(counter-1)
seed.settings = sub.settings
return sub.logger.newChildLog(seed, msg, sub.detached)
}
// Step creates a new logger that does not need to be terminated -- it
// represents the continued execution of the current logger but doing
// something that is different and should be in a fresh span. The expectation
// is that there is a parent logger that is creating various sub-logs using
// Step over and over as it does different things.
func (sub *Sub) Step(msg string, mods ...SeedModifier) *Logger {
seed := sub.logger.capSpan.SubSeed(mods...)
counter := int(atomic.AddInt32(&sub.logger.span.stepCounter, 1))
seed.spanSequenceCode += "." + strconv.Itoa(counter)
seed.settings = sub.settings
return sub.logger.newChildLog(seed, msg, sub.detached)
}
// StackFrames sets the number of stack frames to include at
// a logging level. Levels above the given level will be set to
// get least this many. Levels below the given level will be set
// to receive at most this many.
func (sub *Sub) StackFrames(level xopnum.Level, count int) *Sub {
sub.settings.StackFrames(level, count)
return sub
}
// StackFrames sets the number of stack frames to include at
// a logging level. Levels above the given level will be set to
// get least this many. Levels below the given level will be set
// to receive at most this many.
func (settings *LogSettings) StackFrames(level xopnum.Level, frameCount int) {
for _, l := range xopnum.LevelValues() {
current := settings.stackFramesWanted[l]
if l <= level && current > frameCount {
settings.stackFramesWanted[l] = frameCount
}
if l >= level && current < frameCount {
settings.stackFramesWanted[l] = frameCount
}
}
}
// StackFilenameRewrite is used to rewrite filenames in stack
// traces. Generally this is used to eliminate path prefixes.
// An empty return value indicates that the rest of the stack
// trace should be discarded.
func (sub *Sub) StackFilenameRewrite(f func(string) string) *Sub {
sub.settings.StackFilenameRewrite(f)
return sub
}
// StackFilenameRewrite is used to rewrite filenames in stack
// traces. Generally this is used to eliminate path prefixes.
// An empty return value indicates that the rest of the stack
// trace should be discarded.
func (settings *LogSettings) StackFilenameRewrite(f func(string) string) {
settings.stackFilenameRewrite = f
}
// SynchronousFlush sets the behavior for any Flush()
// triggered by a call to Done(). When true, the
// call to Done() will not return until the Flush() is
// complete.
func (sub *Sub) SynchronousFlush(b bool) *Sub {
sub.settings.SynchronousFlush(b)
return sub
}
// SynchronousFlush sets the behavior for any Flush()
// triggered by a call to Done(). When true, the
// call to Done() will not return until the Flush() is
// complete.
func (settings *LogSettings) SynchronousFlush(b bool) {
settings.synchronousFlushWhenDone = b
}
// MinLevel sets the minimum logging level below which logs will
// be discarded. The default minimum level comes from DefaultSettings.
func (sub *Sub) MinLevel(level xopnum.Level) *Sub {
sub.settings.MinLevel(level)
return sub
}
// MinLevel sets the minimum logging level below which logs will
// be discarded. The default minimum level comes from DefaultSettings.
func (settings *LogSettings) MinLevel(level xopnum.Level) {
settings.minimumLogLevel = level
}
func (settings LogSettings) GetMinLevel() xopnum.Level {
return settings.minimumLogLevel
}
// TagLinesWithSpanSequence controls if the span sequence
// indicator (see Fork() and Step()) should be included in
// the prefill data on each line.
func (sub *Sub) TagLinesWithSpanSequence(b bool) *Sub {
sub.settings.TagLinesWithSpanSequence(b)
return sub
}
// TagLinesWithSpanSequence controls if the span sequence
// indicator (see Fork() and Step()) should be included in
// the prefill data on each line.
func (settings *LogSettings) TagLinesWithSpanSequence(b bool) {
settings.tagLinesWithSpanSequence = b
}
// PrefillText is prepended to any eventual Line.Msg() or Line.Template().
// PrefillText will be ignored for Line.Model() and Line.Link().
func (sub *Sub) PrefillText(m string) *Sub {
sub.settings.PrefillText(m)
return sub
}
// PrefillText is prepended to any eventual Line.Msg() or Line.Template()
// PrefillText will be ignored for Line.Model() and Line.Link().
func (settings *LogSettings) PrefillText(m string) {
settings.prefillMsg = m
}
func (sub *Sub) NoPrefill() *Sub {
sub.settings.NoPrefill()
return sub
}
func (settings *LogSettings) NoPrefill() {
settings.prefillData = nil
settings.prefillMsg = ""
}
func (logger *Logger) sendPrefill() {
if logger.settings.prefillData == nil && logger.settings.prefillMsg == "" && !logger.settings.tagLinesWithSpanSequence {
logger.prefilled = logger.span.base.NoPrefill()
return
}
prefilling := logger.span.base.StartPrefill()
for _, f := range logger.settings.prefillData {
f(prefilling)
}
if logger.settings.tagLinesWithSpanSequence {
prefilling.String(xopconst.SpanSequenceCode.Key(), logger.span.seed.spanSequenceCode, xopbase.StringDataType)
}
logger.prefilled = prefilling.PrefillComplete(logger.settings.prefillMsg)
}
// PrefillEmbeddedEnum is used to set a data element that is included on every log
// line.
// PrefillEmbeddedEnum is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillEmbeddedEnum(k xopat.EmbeddedEnum) *Sub {
sub.settings.PrefillEmbeddedEnum(k)
return sub
}
func (settings *LogSettings) PrefillEmbeddedEnum(k xopat.EmbeddedEnum) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Enum(k.EnumAttribute(), k)
})
}
// PrefillEnum is used to set a data element that is included on every log
// line.
// PrefillEnum is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillEnum(k *xopat.EnumAttribute, v xopat.Enum) *Sub {
sub.settings.PrefillEnum(k, v)
return sub
}
func (settings *LogSettings) PrefillEnum(k *xopat.EnumAttribute, v xopat.Enum) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Enum(k, v)
})
}
// PrefillError is used to set a data element that is included on every log
// line. Errors will always be formatted with v.Error(). Redaction is
// not supported.
func (sub *Sub) PrefillError(k xopat.K, v error) *Sub {
sub.settings.PrefillError(k, v)
return sub
}
// PrefillError is used to set a data element that is included on every log
// line. Errors will always be formatted with v.Error(). Redaction is
// not supported.
func (settings *LogSettings) PrefillError(k xopat.K, v error) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.String(k, v.Error(), xopbase.ErrorDataType)
})
}
// PrefillAny is used to set a data element that is included on every log
// line. Values provided with PrefillAny will be copied
// using https://github.com/mohae/deepcopy 's Copy().
// PrefillAny is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
// Redaction is not supported.
func (sub *Sub) PrefillAny(k xopat.K, v interface{}) *Sub {
sub.settings.PrefillAny(k, v)
return sub
}
// PrefillAny is used to set a data element that is included on every log
// line. Values provided with PrefillAny will be copied
// using https://github.com/mohae/deepcopy 's Copy().
// PrefillAny is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
// Redaction is not supported.
func (settings *LogSettings) PrefillAny(k xopat.K, v interface{}) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Any(k, xopbase.ModelArg{Model: v})
})
}
// PrefillFloat32 is used to set a data element that is included on every log
// line.
// PrefillFloat32 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillFloat32(k xopat.K, v float32) *Sub {
sub.settings.PrefillFloat32(k, v)
return sub
}
func (settings *LogSettings) PrefillFloat32(k xopat.K, v float32) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Float64(k, float64(v), xopbase.Float32DataType)
})
}
// PrefillBool is used to set a data element that is included on every log
// line.
// PrefillBool is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillBool(k xopat.K, v bool) *Sub {
sub.settings.PrefillBool(k, v)
return sub
}
func (settings *LogSettings) PrefillBool(k xopat.K, v bool) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Bool(k, v)
})
}
// PrefillDuration is used to set a data element that is included on every log
// line.
// PrefillDuration is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillDuration(k xopat.K, v time.Duration) *Sub {
sub.settings.PrefillDuration(k, v)
return sub
}
func (settings *LogSettings) PrefillDuration(k xopat.K, v time.Duration) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Duration(k, v)
})
}
// PrefillTime is used to set a data element that is included on every log
// line.
// PrefillTime is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillTime(k xopat.K, v time.Time) *Sub {
sub.settings.PrefillTime(k, v)
return sub
}
func (settings *LogSettings) PrefillTime(k xopat.K, v time.Time) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Time(k, v)
})
}
// PrefillFloat64 is used to set a data element that is included on every log
// line.
// PrefillFloat64 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillFloat64(k xopat.K, v float64) *Sub {
sub.settings.PrefillFloat64(k, v)
return sub
}
func (settings *LogSettings) PrefillFloat64(k xopat.K, v float64) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Float64(k, v, xopbase.Float64DataType)
})
}
// PrefillInt64 is used to set a data element that is included on every log
// line.
// PrefillInt64 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillInt64(k xopat.K, v int64) *Sub {
sub.settings.PrefillInt64(k, v)
return sub
}
func (settings *LogSettings) PrefillInt64(k xopat.K, v int64) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Int64(k, v, xopbase.Int64DataType)
})
}
// PrefillString is used to set a data element that is included on every log
// line.
// PrefillString is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillString(k xopat.K, v string) *Sub {
sub.settings.PrefillString(k, v)
return sub
}
func (settings *LogSettings) PrefillString(k xopat.K, v string) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.String(k, v, xopbase.StringDataType)
})
}
// PrefillUint64 is used to set a data element that is included on every log
// line.
// PrefillUint64 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUint64(k xopat.K, v uint64) *Sub {
sub.settings.PrefillUint64(k, v)
return sub
}
func (settings *LogSettings) PrefillUint64(k xopat.K, v uint64) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, v, xopbase.Uint64DataType)
})
}
// PrefillInt is used to set a data element that is included on every log
// line.
// PrefillInt is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillInt(k xopat.K, v int) *Sub {
sub.settings.PrefillInt(k, v)
return sub
}
func (settings *LogSettings) PrefillInt(k xopat.K, v int) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Int64(k, int64(v), xopbase.IntDataType)
})
}
// PrefillInt16 is used to set a data element that is included on every log
// line.
// PrefillInt16 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillInt16(k xopat.K, v int16) *Sub {
sub.settings.PrefillInt16(k, v)
return sub
}
func (settings *LogSettings) PrefillInt16(k xopat.K, v int16) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Int64(k, int64(v), xopbase.Int16DataType)
})
}
// PrefillInt32 is used to set a data element that is included on every log
// line.
// PrefillInt32 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillInt32(k xopat.K, v int32) *Sub {
sub.settings.PrefillInt32(k, v)
return sub
}
func (settings *LogSettings) PrefillInt32(k xopat.K, v int32) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Int64(k, int64(v), xopbase.Int32DataType)
})
}
// PrefillInt8 is used to set a data element that is included on every log
// line.
// PrefillInt8 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillInt8(k xopat.K, v int8) *Sub {
sub.settings.PrefillInt8(k, v)
return sub
}
func (settings *LogSettings) PrefillInt8(k xopat.K, v int8) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Int64(k, int64(v), xopbase.Int8DataType)
})
}
// PrefillUint is used to set a data element that is included on every log
// line.
// PrefillUint is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUint(k xopat.K, v uint) *Sub {
sub.settings.PrefillUint(k, v)
return sub
}
func (settings *LogSettings) PrefillUint(k xopat.K, v uint) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, uint64(v), xopbase.UintDataType)
})
}
// PrefillUint16 is used to set a data element that is included on every log
// line.
// PrefillUint16 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUint16(k xopat.K, v uint16) *Sub {
sub.settings.PrefillUint16(k, v)
return sub
}
func (settings *LogSettings) PrefillUint16(k xopat.K, v uint16) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, uint64(v), xopbase.Uint16DataType)
})
}
// PrefillUint32 is used to set a data element that is included on every log
// line.
// PrefillUint32 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUint32(k xopat.K, v uint32) *Sub {
sub.settings.PrefillUint32(k, v)
return sub
}
func (settings *LogSettings) PrefillUint32(k xopat.K, v uint32) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, uint64(v), xopbase.Uint32DataType)
})
}
// PrefillUint8 is used to set a data element that is included on every log
// line.
// PrefillUint8 is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUint8(k xopat.K, v uint8) *Sub {
sub.settings.PrefillUint8(k, v)
return sub
}
func (settings *LogSettings) PrefillUint8(k xopat.K, v uint8) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, uint64(v), xopbase.Uint8DataType)
})
}
// PrefillUintptr is used to set a data element that is included on every log
// line.
// PrefillUintptr is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Logger() is called.
func (sub *Sub) PrefillUintptr(k xopat.K, v uintptr) *Sub {
sub.settings.PrefillUintptr(k, v)
return sub
}
func (settings *LogSettings) PrefillUintptr(k xopat.K, v uintptr) {
settings.prefillData = append(settings.prefillData, func(line xopbase.Prefilling) {
line.Uint64(k, uint64(v), xopbase.UintptrDataType)
})
}
// SetRedactAnyFunc sets a redaction function to be used
// when Line.Any() is called.
func (sub *Sub) SetRedactAnyFunc(f RedactAnyFunc) *Sub {
sub.settings.SetRedactAnyFunc(f)
return sub
}
// SetRedactErrorFunc sets a redaction function to be used
// when Line.Error() is called.
func (sub *Sub) SetRedactErrorFunc(f RedactErrorFunc) *Sub {
sub.settings.SetRedactErrorFunc(f)
return sub
}
// SetRedactStringFunc sets a redaction function to be used
// when Line.String() is called.
func (sub *Sub) SetRedactStringFunc(f RedactStringFunc) *Sub {
sub.settings.SetRedactStringFunc(f)
return sub
}
// SetRedactAnyFunc sets a redaction function to be used
// when Line.Any() is called.
func (settings *LogSettings) SetRedactAnyFunc(f RedactAnyFunc) {
settings.redactAny = f
}
// SetRedactErrorFunc sets a redaction function to be used
// when Line.Error() is called.
func (settings *LogSettings) SetRedactErrorFunc(f RedactErrorFunc) {
settings.redactError = f
}
// SetRedactStringFunc sets a redaction function to be used
// when Line.String() is called.
func (settings *LogSettings) SetRedactStringFunc(f RedactStringFunc) {
settings.redactString = f
}