The returned Field will safelyand explicitly represent `nil` when appropriate.Array constructs a field with the given key and ArrayMarshaler. (For more advanced use cases, they alsoaccept strongly typed fields - see the SugaredLogger.With documentation fordetails. Logging levels in winston conform to the severity ordering specified by RFC5424; severity of all levels is assumed to be numerically ascending from most important to least important. The returned Field will safelyand explicitly represent `nil` when appropriate.SetLevel alters the logging level.Error logs a message at ErrorLevel. For the standard levels, we have ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF. See the zapcore documentation for details.In contexts where performance is nice, but not critical, use theSugaredLogger. By building thehigh-level SugaredLogger on that foundation, zap lets users choose whenthey need to count every allocation and when they'd prefer a more familiar,loosely typed API.The zap package itself is a relatively thin wrapper around the interfacesin go.uber.org/zap/zapcore. Passing an orphaned key triggers similar behavior:panics in development and errors in production.The simplest way to build a Logger is to use zap's opinionated presets:NewExample, NewProduction, and NewDevelopment. OWASP Security Logging on the main website for The OWASP Foundation. The returned Field will safelyand explicitly represent `nil` when appropriate.The supplied WriteSyncer must be safe for concurrent use. It includes a reflection-free, zero-allocation JSON encoder, and the base Logger strives to avoid serialization overhead and allocations
For most users, zap's Configstruct strikes the right balance between flexibility and convenience. By default, the "json" and "console" encoders areregistered.Complex64 constructs a field that carries a complex number.
Sampling caps theglobal CPU and I/O load that logging puts on your process while attemptingto preserve a representative subset of your logs.Uint16p constructs a field that carries a *uint16. Seethe package-level BasicConfiguration example for sample code.Infof uses fmt.Sprintf to log a templated message.Info uses fmt.Sprint to construct and log a message.Package zap provides fast, structured, leveled logging.Sync calls the underlying Core's Sync method, flushing any buffered logentries.
If no inputs are supplied, it returns a no-opWriteSyncer.AtomicLevels must be created with the NewAtomicLevel constructor to allocatetheir internal atomic pointer.Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.For an example showing runtime log level changes, see the documentation forAtomicLevel.Fatal logs a message at FatalLevel. These presets build a logger with a single function call: logger, err := zap.NewProduction() if err != nil { log.Fatalf("can't initialize zap logger: %v", err) } defer logger.Sync() It also returns any error encountered and a function to closeany opened files.Level returns the minimum enabled log level.The logger then calls os.Exit(1), even if logging at FatalLevel isdisabled.Binary data is serialized in an encoding-appropriate format. Errors which also implement fmt.Formatter (like those producedby github.com/pkg/errors) will also have their verbose representation storedunder key+"Verbose". Unlike mostnumeric fields, this costs an allocation (to convert the complex128 tointerface{}).Float64s constructs a field that carries a slice of floats.Debugw logs a message with some additional context. The Stringer's String method is called lazily.Enabled calls the wrapped function.A SugaredLogger wraps the base Logger functionality in a slower, but lessverbose, API.
An opinionated logger interface and collection of logging best practices with adapters and integrations for well-known libraries (logrus, go-kit log, zap, zerolog, etc).
The variadic key-valuepairs are treated as they are in With.Uint16s constructs a field that carries a slice of unsigned integers.Note that the keys in key-value pairs should be strings. See Logger.Named for details.Note that Config intentionally supports only the most common options.