MCPcopy Create free account
hub / github.com/DoNewsCode/core / ExampleWithContext

Function ExampleWithContext

logging/example_test.go:50–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func ExampleWithContext() {
51 bag, ctx := ctxmeta.Inject(context.Background())
52 bag.Set("clientIp", "127.0.0.1")
53 bag.Set("requestUrl", "/example")
54 bag.Set("transport", "http")
55 logger := logging.NewLogger("json")
56 ctxLogger := logging.WithContext(logger, ctx)
57 ctxLogger.Log("foo", "bar")
58 // Output:
59 // {"clientIp":"127.0.0.1","foo":"bar","requestUrl":"/example","transport":"http"}
60}

Callers

nothing calls this directly

Calls 5

InjectFunction · 0.92
NewLoggerFunction · 0.92
WithContextFunction · 0.92
LogMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected