Example of using the Output function in the log package to change the output destination
()
| 158 | |
| 159 | // Example of using the Output function in the log package to change the output destination |
| 160 | func 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 |
| 173 | func ExampleWith() { |