MCPcopy Create free account
hub / github.com/coder/slog / LogEntry

Method LogEntry

sloggers/slogjson/slogjson.go:45–75  ·  view source on GitHub ↗
(ctx context.Context, ent slog.SinkEntry)

Source from the content-addressed store, hash-verified

43}
44
45func (s jsonSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
46 m := slog.M(
47 slog.F("ts", ent.Time),
48 slog.F("level", ent.Level),
49 slog.F("msg", ent.Message),
50 slog.F("caller", fmt.Sprintf("%v:%v", ent.File, ent.Line)),
51 slog.F("func", ent.Func),
52 )
53
54 if len(ent.LoggerNames) > 0 {
55 m = append(m, slog.F("logger_names", ent.LoggerNames))
56 }
57
58 if ent.SpanContext.IsValid() {
59 m = append(m,
60 slog.F("trace", ent.SpanContext.TraceID()),
61 slog.F("span", ent.SpanContext.SpanID()),
62 )
63 }
64
65 if len(ent.Fields) > 0 {
66 m = append(m,
67 slog.F("fields", ent.Fields),
68 )
69 }
70
71 buf, _ := json.Marshal(m)
72
73 buf = append(buf, '\n')
74 s.w.Write("slogjson", buf)
75}
76
77func (s jsonSink) Sync() {
78 s.w.Sync("slogjson")

Callers

nothing calls this directly

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected