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

Method buildOptions

config.go:264–313  ·  config.go::Config.buildOptions
(errSink zapcore.WriteSyncer)

Source from the content-addressed store, hash-verified

262}
263
264func (cfg Config) buildOptions(errSink zapcore.WriteSyncer) []Option {
265 opts := []Option{ErrorOutput(errSink)}
266
267 if cfg.Development {
268 opts = append(opts, Development())
269 }
270
271 if !cfg.DisableCaller {
272 opts = append(opts, AddCaller())
273 }
274
275 stackLevel := ErrorLevel
276 if cfg.Development {
277 stackLevel = WarnLevel
278 }
279 if !cfg.DisableStacktrace {
280 opts = append(opts, AddStacktrace(stackLevel))
281 }
282
283 if scfg := cfg.Sampling; scfg != nil {
284 opts = append(opts, WrapCore(func(core zapcore.Core) zapcore.Core {
285 var samplerOpts []zapcore.SamplerOption
286 if scfg.Hook != nil {
287 samplerOpts = append(samplerOpts, zapcore.SamplerHook(scfg.Hook))
288 }
289 return zapcore.NewSamplerWithOptions(
290 core,
291 time.Second,
292 cfg.Sampling.Initial,
293 cfg.Sampling.Thereafter,
294 samplerOpts...,
295 )
296 }))
297 }
298
299 if len(cfg.InitialFields) > 0 {
300 fs := make([]Field, 0, len(cfg.InitialFields))
301 keys := make([]string, 0, len(cfg.InitialFields))
302 for k := range cfg.InitialFields {
303 keys = append(keys, k)
304 }
305 sort.Strings(keys)
306 for _, k := range keys {
307 fs = append(fs, Any(k, cfg.InitialFields[k]))
308 }
309 opts = append(opts, Fields(fs...))
310 }
311
312 return opts
313}
314
315func (cfg Config) openSinks() (zapcore.WriteSyncer, zapcore.WriteSyncer, error) {
316 sink, closeOut, err := Open(cfg.OutputPaths...)

Callers 1

BuildMethod · 0.95

Calls 9

SamplerHookFunction · 0.92
NewSamplerWithOptionsFunction · 0.92
ErrorOutputFunction · 0.85
DevelopmentFunction · 0.85
AddCallerFunction · 0.85
AddStacktraceFunction · 0.85
WrapCoreFunction · 0.85
AnyFunction · 0.85
FieldsFunction · 0.85

Tested by

no test coverage detected