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

Function TestMake

sloggers/slogjson/slogjson_test.go:24–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22var bg = context.Background()
23
24func TestMake(t *testing.T) {
25 t.Parallel()
26
27 tp := sdktrace.NewTracerProvider()
28 tracer := tp.Tracer("tracer")
29 ctx, span := tracer.Start(bg, "trace")
30 span.End()
31 _ = tp.Shutdown(bg)
32 b := &bytes.Buffer{}
33 l := slog.Make(slogjson.Sink(b))
34 l = l.Named("named")
35 l.Error(ctx, "line1\n\nline2", slog.F("wowow", "me\nyou"))
36
37 j := entryjson.Filter(b.String(), "ts")
38 exp := fmt.Sprintf(`{"level":"ERROR","msg":"line1\n\nline2","caller":"%v:35","func":"cdr.dev/slog/v3/sloggers/slogjson_test.TestMake","logger_names":["named"],"trace":"%v","span":"%v","fields":{"wowow":"me\nyou"}}
39`, slogjsonTestFile, span.SpanContext().TraceID().String(), span.SpanContext().SpanID().String())
40 assert.Equal(t, "entry", exp, j)
41}
42
43func TestNoDriverValue(t *testing.T) {
44 t.Parallel()

Callers

nothing calls this directly

Calls 6

SinkFunction · 0.92
FilterFunction · 0.92
EqualFunction · 0.92
NamedMethod · 0.80
StringMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected