MCPcopy Index your code
hub / github.com/DoNewsCode/core / Example_sprintf

Function Example_sprintf

logging/example_test.go:34–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34func Example_sprintf() {
35 logger := logging.NewLogger("json")
36 // Set log level to info
37 logger = level.NewFilter(logger, level.AllowInfo())
38 levelLogger := logging.WithLevel(logger)
39
40 // Let's try to log some debug messages. They are filtered by log level, so you should see no output.
41 // The cost of fmt.Sprintf is paid event if the log is filtered out. This sometimes can be a huge performance downside.
42 levelLogger.Debugw("record some data", "data", fmt.Sprintf("%+v", []int{1, 2, 3}))
43 // Or better, we can use logging.Sprintf to avoid the cost if the log is not actually written to the output.
44 levelLogger.Debugw("record some data", "data", logging.Sprintf("%+v", []int{1, 2, 3}))
45
46 // Output:
47 //
48}
49
50func ExampleWithContext() {
51 bag, ctx := ctxmeta.Inject(context.Background())

Callers

nothing calls this directly

Calls 5

NewLoggerFunction · 0.92
WithLevelFunction · 0.92
SprintfFunction · 0.92
DebugwMethod · 0.65
SprintfMethod · 0.65

Tested by

no test coverage detected