MCPcopy
hub / github.com/uber-go/zap / ExampleAtomicLevel_config

Function ExampleAtomicLevel_config

example_test.go:260–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

258}
259
260func ExampleAtomicLevel_config() {
261 // The zap.Config struct includes an AtomicLevel. To use it, keep a
262 // reference to the Config.
263 rawJSON := []byte(`{
264 "level": "info",
265 "outputPaths": ["stdout"],
266 "errorOutputPaths": ["stderr"],
267 "encoding": "json",
268 "encoderConfig": {
269 "messageKey": "message",
270 "levelKey": "level",
271 "levelEncoder": "lowercase"
272 }
273 }`)
274 var cfg zap.Config
275 if err := json.Unmarshal(rawJSON, &cfg); err != nil {
276 panic(err)
277 }
278 logger := zap.Must(cfg.Build())
279 defer logger.Sync()
280
281 logger.Info("info logging enabled")
282
283 cfg.Level.SetLevel(zap.ErrorLevel)
284 logger.Info("info logging disabled")
285 // Output:
286 // {"level":"info","message":"info logging enabled"}
287}
288
289func ExampleLogger_Check() {
290 logger := zap.NewExample()

Callers

nothing calls this directly

Calls 5

BuildMethod · 0.95
MustFunction · 0.92
SetLevelMethod · 0.80
SyncMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected