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

Method Build

config.go:239–262  ·  view source on GitHub ↗

Build constructs a logger from the Config and Options.

(opts ...Option)

Source from the content-addressed store, hash-verified

237
238// Build constructs a logger from the Config and Options.
239func (cfg Config) Build(opts ...Option) (*Logger, error) {
240 enc, err := cfg.buildEncoder()
241 if err != nil {
242 return nil, err
243 }
244
245 sink, errSink, err := cfg.openSinks()
246 if err != nil {
247 return nil, err
248 }
249
250 if cfg.Level == (AtomicLevel{}) {
251 return nil, errors.New("missing Level")
252 }
253
254 log := New(
255 zapcore.NewCore(enc, sink, cfg.Level),
256 cfg.buildOptions(errSink)...,
257 )
258 if len(opts) > 0 {
259 log = log.WithOptions(opts...)
260 }
261 return log, nil
262}
263
264func (cfg Config) buildOptions(errSink zapcore.WriteSyncer) []Option {
265 opts := []Option{ErrorOutput(errSink)}

Callers 8

TestConfigFunction · 0.80
NewProductionFunction · 0.80
NewDevelopmentFunction · 0.80

Calls 6

buildEncoderMethod · 0.95
openSinksMethod · 0.95
buildOptionsMethod · 0.95
NewCoreFunction · 0.92
NewFunction · 0.70
WithOptionsMethod · 0.45

Tested by 6

TestConfigFunction · 0.64