(errSink zapcore.WriteSyncer)
| 262 | } |
| 263 | |
| 264 | func (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 | |
| 315 | func (cfg Config) openSinks() (zapcore.WriteSyncer, zapcore.WriteSyncer, error) { |
| 316 | sink, closeOut, err := Open(cfg.OutputPaths...) |
no test coverage detected