New constructs a new Logger from the provided zapcore.Core and Options. If the passed zapcore.Core is nil, it falls back to using a no-op implementation. This is the most flexible way to construct a Logger, but also the most verbose. For typical use cases, the highly-opinionated presets (NewProduct
(core zapcore.Core, options ...Option)
| 67 | // |
| 68 | // For sample code, see the package-level AdvancedConfiguration example. |
| 69 | func New(core zapcore.Core, options ...Option) *Logger { |
| 70 | if core == nil { |
| 71 | return NewNop() |
| 72 | } |
| 73 | log := &Logger{ |
| 74 | core: core, |
| 75 | errorOutput: zapcore.Lock(os.Stderr), |
| 76 | addStack: zapcore.FatalLevel + 1, |
| 77 | clock: zapcore.DefaultClock, |
| 78 | } |
| 79 | return log.WithOptions(options...) |
| 80 | } |
| 81 | |
| 82 | // NewNop returns a no-op Logger. It never writes out logs or internal errors, |
| 83 | // and it never runs user-defined hooks. |