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

Function New

logger.go:69–80  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

67//
68// For sample code, see the package-level AdvancedConfiguration example.
69func 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.

Callers 15

ExampleAtomicLevelFunction · 0.92
withLoggerFunction · 0.92
TestWriterFunction · 0.92
TestWrite_SyncFunction · 0.92
BenchmarkWriterFunction · 0.92
NewLoggerFunction · 0.92
TestObserverFunction · 0.92
withLoggerFunction · 0.92
TestLoggerV2Function · 0.92
newZapLoggerFunction · 0.92
newSampledLoggerFunction · 0.92

Calls 3

WithOptionsMethod · 0.95
LockFunction · 0.92
NewNopFunction · 0.85

Tested by 15

ExampleAtomicLevelFunction · 0.74
withLoggerFunction · 0.74
TestWriterFunction · 0.74
TestWrite_SyncFunction · 0.74
BenchmarkWriterFunction · 0.74
TestObserverFunction · 0.74
withLoggerFunction · 0.74
TestLoggerV2Function · 0.74
newZapLoggerFunction · 0.74
newSampledLoggerFunction · 0.74
withLoggerFunction · 0.56