[VOL-4291] OfAgent changes for gRPC migration
Change-Id: I8da1db6df49d478ef24ec8f9bd719e9692f48a7f
diff --git a/vendor/go.uber.org/zap/config.go b/vendor/go.uber.org/zap/config.go
index 6fe17d9..55637fb 100644
--- a/vendor/go.uber.org/zap/config.go
+++ b/vendor/go.uber.org/zap/config.go
@@ -21,6 +21,7 @@
package zap
import (
+ "fmt"
"sort"
"time"
@@ -31,10 +32,14 @@
// global CPU and I/O load that logging puts on your process while attempting
// to preserve a representative subset of your logs.
//
-// Values configured here are per-second. See zapcore.NewSampler for details.
+// If specified, the Sampler will invoke the Hook after each decision.
+//
+// Values configured here are per-second. See zapcore.NewSamplerWithOptions for
+// details.
type SamplingConfig struct {
- Initial int `json:"initial" yaml:"initial"`
- Thereafter int `json:"thereafter" yaml:"thereafter"`
+ Initial int `json:"initial" yaml:"initial"`
+ Thereafter int `json:"thereafter" yaml:"thereafter"`
+ Hook func(zapcore.Entry, zapcore.SamplingDecision) `json:"-" yaml:"-"`
}
// Config offers a declarative way to construct a logger. It doesn't do
@@ -96,6 +101,7 @@
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
+ FunctionKey: zapcore.OmitKey,
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
@@ -135,6 +141,7 @@
LevelKey: "L",
NameKey: "N",
CallerKey: "C",
+ FunctionKey: zapcore.OmitKey,
MessageKey: "M",
StacktraceKey: "S",
LineEnding: zapcore.DefaultLineEnding,
@@ -174,6 +181,10 @@
return nil, err
}
+ if cfg.Level == (AtomicLevel{}) {
+ return nil, fmt.Errorf("missing Level")
+ }
+
log := New(
zapcore.NewCore(enc, sink, cfg.Level),
cfg.buildOptions(errSink)...,
@@ -203,9 +214,19 @@
opts = append(opts, AddStacktrace(stackLevel))
}
- if cfg.Sampling != nil {
+ if scfg := cfg.Sampling; scfg != nil {
opts = append(opts, WrapCore(func(core zapcore.Core) zapcore.Core {
- return zapcore.NewSampler(core, time.Second, int(cfg.Sampling.Initial), int(cfg.Sampling.Thereafter))
+ var samplerOpts []zapcore.SamplerOption
+ if scfg.Hook != nil {
+ samplerOpts = append(samplerOpts, zapcore.SamplerHook(scfg.Hook))
+ }
+ return zapcore.NewSamplerWithOptions(
+ core,
+ time.Second,
+ cfg.Sampling.Initial,
+ cfg.Sampling.Thereafter,
+ samplerOpts...,
+ )
}))
}