Example of using the With function to add context fields
()
| 171 | |
| 172 | // Example of using the With function to add context fields |
| 173 | func ExampleWith() { |
| 174 | setup() |
| 175 | |
| 176 | // you have to assign the result of With() to a new Logger and can't inline the level calls |
| 177 | // because they need a *Logger receiver |
| 178 | augmented := log.With().Str("service", "myservice").Logger() |
| 179 | augmented.Info().Msg("hello world") |
| 180 | // Output: {"level":"info","service":"myservice","time":1199811905,"message":"hello world"} |
| 181 | } |
| 182 | |
| 183 | // Example of using the Level function to set the log level |
| 184 | func ExampleLevel() { |