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

Function ExampleDictObject

example_test.go:391–434  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

389}
390
391func ExampleDictObject() {
392 logger := zap.NewExample()
393 defer logger.Sync()
394
395 // Use DictObject to create zapcore.ObjectMarshaler implementations from Field arrays,
396 // then use the Object and Objects field constructors to turn them back into a Field.
397
398 logger.Debug("worker received job",
399 zap.Object("w1",
400 zap.DictObject(
401 zap.Int("id", 402000),
402 zap.String("description", "compress image data"),
403 zap.Int("priority", 3),
404 ),
405 ))
406
407 d1 := 68 * time.Millisecond
408 d2 := 79 * time.Millisecond
409 d3 := 57 * time.Millisecond
410
411 logger.Info("worker status checks",
412 zap.Objects("job batch enqueued",
413 []zapcore.ObjectMarshaler{
414 zap.DictObject(
415 zap.String("worker", "w1"),
416 zap.Int("load", 419),
417 zap.Duration("latency", d1),
418 ),
419 zap.DictObject(
420 zap.String("worker", "w2"),
421 zap.Int("load", 520),
422 zap.Duration("latency", d2),
423 ),
424 zap.DictObject(
425 zap.String("worker", "w3"),
426 zap.Int("load", 310),
427 zap.Duration("latency", d3),
428 ),
429 },
430 ))
431 // Output:
432 // {"level":"debug","msg":"worker received job","w1":{"id":402000,"description":"compress image data","priority":3}}
433 // {"level":"info","msg":"worker status checks","job batch enqueued":[{"worker":"w1","load":419,"latency":"68ms"},{"worker":"w2","load":520,"latency":"79ms"},{"worker":"w3","load":310,"latency":"57ms"}]}
434}
435
436func ExampleObjectValues() {
437 logger := zap.NewExample()

Callers

nothing calls this directly

Calls 10

NewExampleFunction · 0.92
ObjectFunction · 0.92
DictObjectFunction · 0.92
IntFunction · 0.92
StringFunction · 0.92
ObjectsFunction · 0.92
DurationFunction · 0.92
SyncMethod · 0.65
DebugMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected