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

Function ExampleAtomicLevel

example_test.go:238–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236}
237
238func 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
260func ExampleAtomicLevel_config() {
261 // The zap.Config struct includes an AtomicLevel. To use it, keep a

Callers

nothing calls this directly

Calls 9

SetLevelMethod · 0.95
NewAtomicLevelFunction · 0.92
NewFunction · 0.92
NewCoreFunction · 0.92
NewJSONEncoderFunction · 0.92
LockFunction · 0.92
SyncMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected