Example of using the Ctx function in the log package to log with context
()
| 224 | |
| 225 | // Example of using the Ctx function in the log package to log with context |
| 226 | func ExampleCtx() { |
| 227 | setup() |
| 228 | |
| 229 | hooked := log.Hook(captainHook) |
| 230 | ctx := context.WithValue(context.Background(), valueKey, "12345") |
| 231 | logger := hooked.With().Ctx(ctx).Logger() |
| 232 | log.Ctx(logger.WithContext(ctx)).Info().Msg("hello world") |
| 233 | // Output: {"level":"info","time":1199811905,"key":"12345","is_error":false,"msg_len":11,"message":"hello world"} |
| 234 | } |
| 235 | |
| 236 | // Example of using the Sample function in the log package to set a sampler |
| 237 | func ExampleSample() { |