Documentation ¶
Index ¶
- func DP(msg string, err error, fields ...Field)
- func DPanic(msg string, fields ...Field)
- func Debug(msg string, fields ...Field)
- func E(msg string, err error, fields ...Field)
- func Error(msg string, fields ...Field)
- func F(msg string, err error, fields ...Field)
- func Fatal(msg string, fields ...Field)
- func InDevelopment(opts ...Option)
- func InProduction(opts ...Option)
- func Info(msg string, fields ...Field)
- func Named(s string)
- func P(msg string, err error, fields ...Field)
- func Panic(msg string, fields ...Field)
- func Sync() error
- func Warn(msg string, fields ...Field)
- func With(fields ...Field)
- func WithCallerSkip(skip int)
- func WithOptions(opts ...Option)
- type Config
- type Field
- func Any(key string, value interface{}) Field
- func Array(key string, val zapcore.ArrayMarshaler) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Bools(key string, bs ...bool) Field
- func ByteString(key string, val []byte) Field
- func ByteStrings(key string, bss ...[]byte) Field
- func Complex128(key string, val complex128) Field
- func Complex128s(key string, nums ...complex128) Field
- func Complex64(key string, val complex64) Field
- func Complex64s(key string, nums ...complex64) Field
- func Duration(key string, val time.Duration) Field
- func Durations(key string, ds ...time.Duration) Field
- func ErrorF(err error) Field
- func ErrorField(err error) Field
- func Errors(key string, errs ...error) Field
- func Float32(key string, val float32) Field
- func Float32s(key string, nums ...float32) Field
- func Float64(key string, val float64) Field
- func Float64s(key string, nums ...float64) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int16s(key string, nums ...int16) Field
- func Int32(key string, val int32) Field
- func Int32s(key string, nums ...int32) Field
- func Int64(key string, val int64) Field
- func Int64s(key string, nums ...int64) Field
- func Int8(key string, val int8) Field
- func Int8s(key string, nums ...int8) Field
- func Ints(key string, nums ...int) Field
- func NamedError(key string, err error) Field
- func Namespace(key string) Field
- func Object(key string, val zapcore.ObjectMarshaler) Field
- func Reflect(key string, val interface{}) Field
- func Skip() Field
- func Stack(key string) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Strings(key string, ss ...string) Field
- func Time(key string, val time.Time) Field
- func Times(key string, ts ...time.Time) Field
- func Uint(key string, val uint) Field
- func Uint16(key string, val uint16) Field
- func Uint16s(key string, nums ...uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint32s(key string, nums ...uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint64s(key string, nums ...uint64) Field
- func Uint8(key string, val uint8) Field
- func Uint8s(key string, nums ...uint8) Field
- func Uintptr(key string, val uintptr) Field
- func Uintptrs(key string, us ...uintptr) Field
- func Uints(key string, nums ...uint) Field
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DP ¶ added in v0.3.0
DP logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func DPanic ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
Example ¶
defer func() { recover() }() DPanic("DPanic level message", Time("time", time.Now().Local()))
Output:
func Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
Example ¶
Debug("Debug level message", Time("time", time.Now().Local()), Ints("Ints", 1, 2), Any("Any", []int{1, 2}))
Output:
func E ¶ added in v0.3.0
E logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
Example ¶
Error("Error level message", Time("time", time.Now().Local()))
Output:
func F ¶ added in v0.3.0
F logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
Example ¶
Error("Fatal level message", Time("time", time.Now().Local()))
Output:
func InDevelopment ¶
func InDevelopment(opts ...Option)
InDevelopment is a reasonable development logging configuration. Logging is enabled at DebugLevel and above.
It enables development mode (which makes DPanicLevel logs panic), uses a console encoder, writes to standard error, and disables sampling. StackTraces are automatically included on logs of WarnLevel and above.
func InProduction ¶
func InProduction(opts ...Option)
InProduction is a reasonable production logging configuration. Logging is enabled at InfoLevel and above.
It uses a JSON encoder, writes to standard error, and enables sampling. StackTraces are automatically included on logs of ErrorLevel and above.
func Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
Example ¶
Info("Info level message", Time("time", time.Now().Local()))
Output:
func Named ¶
func Named(s string)
Named adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.
func P ¶ added in v0.3.0
P logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
Example ¶
defer func() { recover() }() Panic("Panic level message", Time("time", time.Now().Local()))
Output:
func Sync ¶
func Sync() error
Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.
func Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
Example ¶
Warn("Warn level message", Time("time", time.Now().Local()))
Output:
func With ¶
func With(fields ...Field)
With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.
func WithCallerSkip ¶
func WithCallerSkip(skip int)
WithCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option).
Types ¶
type Field ¶
func Any ¶
Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between them. To minimize surprises, []byte values are treated as binary blobs, byte values are treated as uint8, and runes are always treated as integers.
func Array ¶
func Array(key string, val zapcore.ArrayMarshaler) Field
Array constructs a field with the given key and ArrayMarshaler. It provides a flexible, but still type-safe and efficient, way to add array-like types to the logging context. The struct's MarshalLogArray method is called lazily.
func Binary ¶
Binary constructs a field that carries an opaque binary blob.
Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.
func ByteString ¶
ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.
func ByteStrings ¶
ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.
func Complex128 ¶
func Complex128(key string, val complex128) Field
Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).
func Complex128s ¶
func Complex128s(key string, nums ...complex128) Field
Complex128s constructs a field that carries a slice of complex numbers.
func Complex64 ¶
Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).
func Complex64s ¶
Complex64s constructs a field that carries a slice of complex numbers.
func Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func ErrorF ¶
ErrorF is shorthand for the common idiom NamedError("error", err). Deprecated: use ErrorField make more semantic sense.
func ErrorField ¶ added in v0.2.2
ErrorField is shorthand for the common idiom NamedError("error", err).
func Float32 ¶
Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Float64 ¶
Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func NamedError ¶
NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.
For the common case in which the key is simply "error", the Error function is shorter and less repetitive.
func Namespace ¶
Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.
This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.
func Object ¶
func Object(key string, val zapcore.ObjectMarshaler) Field
Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.
func Reflect ¶
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func Skip ¶
func Skip() Field
Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.
func Stack ¶
Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.
func Stringer ¶
Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Time ¶
Time constructs a Field with the given key and value. The encoder controls how the time is serialized.
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
bufferpool
Package bufferpool houses zap's shared internal buffer pool.
|
Package bufferpool houses zap's shared internal buffer pool. |