MCPcopy
hub / github.com/rs/zerolog / ExampleOutput

Function ExampleOutput

log/log_example_test.go:160–170  ·  view source on GitHub ↗

Example of using the Output function in the log package to change the output destination

()

Source from the content-addressed store, hash-verified

158
159// Example of using the Output function in the log package to change the output destination
160func ExampleOutput() {
161 setup()
162
163 out := &bytes.Buffer{}
164 tee := log.Output(out)
165 tee.Info().Msg("hello world")
166 written := out.Len()
167
168 log.Info().Int("bytes", written).Msg("wrote")
169 // Output: {"level":"info","bytes":59,"time":1199811905,"message":"wrote"}
170}
171
172// Example of using the With function to add context fields
173func ExampleWith() {

Callers

nothing calls this directly

Calls 6

OutputFunction · 0.92
InfoFunction · 0.92
setupFunction · 0.85
MsgMethod · 0.80
InfoMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected