()
| 236 | } |
| 237 | |
| 238 | func ExampleAtomicLevel() { |
| 239 | atom := zap.NewAtomicLevel() |
| 240 | |
| 241 | // To keep the example deterministic, disable timestamps in the output. |
| 242 | encoderCfg := zap.NewProductionEncoderConfig() |
| 243 | encoderCfg.TimeKey = "" |
| 244 | |
| 245 | logger := zap.New(zapcore.NewCore( |
| 246 | zapcore.NewJSONEncoder(encoderCfg), |
| 247 | zapcore.Lock(os.Stdout), |
| 248 | atom, |
| 249 | )) |
| 250 | defer logger.Sync() |
| 251 | |
| 252 | logger.Info("info logging enabled") |
| 253 | |
| 254 | atom.SetLevel(zap.ErrorLevel) |
| 255 | logger.Info("info logging disabled") |
| 256 | // Output: |
| 257 | // {"level":"info","msg":"info logging enabled"} |
| 258 | } |
| 259 | |
| 260 | func ExampleAtomicLevel_config() { |
| 261 | // The zap.Config struct includes an AtomicLevel. To use it, keep a |
nothing calls this directly
no test coverage detected