MCPcopy
hub / github.com/kopia/kopia / Emit

Function Emit

internal/contentlog/contentlog_logger.go:26–59  ·  view source on GitHub ↗

Emit writes the entry to the segment writer. We are using this particular syntax to avoid allocating an intermediate interface value. This allows exactly zero non-amortized allocations in all cases.

(ctx context.Context, l *Logger, entry T)

Source from the content-addressed store, hash-verified

24// We are using this particular syntax to avoid allocating an intermediate interface value.
25// This allows exactly zero non-amortized allocations in all cases.
26func Emit[T WriterTo](ctx context.Context, l *Logger, entry T) {
27 if l == nil {
28 return
29 }
30
31 if l.output == nil {
32 return
33 }
34
35 jw := NewJSONWriter()
36 defer jw.Release()
37
38 jw.BeginObject()
39 jw.TimeField("t", l.timeFunc())
40
41 for _, param := range l.params {
42 param.WriteValueTo(jw)
43 }
44
45 params := ctx.Value(loggerParamsKey)
46 if params != nil {
47 if params, ok := params.([]ParamWriter); ok {
48 for _, p := range params {
49 p.WriteValueTo(jw)
50 }
51 }
52 }
53
54 entry.WriteTo(jw)
55 jw.EndObject()
56 jw.buf = append(jw.buf, '\n')
57
58 l.output(jw.buf)
59}
60
61// Log logs a message with no parameters.
62func Log(ctx context.Context, l *Logger, text string) {

Callers 8

TestEmitFunction · 0.92
LogFunction · 0.85
Log1Function · 0.85
Log2Function · 0.85
Log3Function · 0.85
Log4Function · 0.85
Log5Function · 0.85
Log6Function · 0.85

Calls 8

ReleaseMethod · 0.95
BeginObjectMethod · 0.95
TimeFieldMethod · 0.95
EndObjectMethod · 0.95
NewJSONWriterFunction · 0.85
WriteValueToMethod · 0.65
WriteToMethod · 0.65
outputMethod · 0.45

Tested by 1

TestEmitFunction · 0.74