logs

package
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any added in v1.1.7

func Any(key string, value interface{}) zap.Field

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 Binary added in v1.1.7

func Binary(key string, val []byte) zap.Field

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 Bool added in v1.1.7

func Bool(key string, val bool) zap.Field

Bool constructs a field that carries a bool.

func Boolp added in v1.1.7

func Boolp(key string, val *bool) zap.Field

Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.

func ByteString added in v1.1.7

func ByteString(key string, val []byte) zap.Field

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 Clear added in v1.1.4

func Clear()

Clear clear all logs

func Complex128 added in v1.1.7

func Complex128(key string, val complex128) zap.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 Complex128p added in v1.1.7

func Complex128p(key string, val *complex128) zap.Field

Complex128p constructs a field that carries a *complex128. The returned Field will safely and explicitly represent `nil` when appropriate.

func Complex64 added in v1.1.7

func Complex64(key string, val complex64) zap.Field

Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).

func Complex64p added in v1.1.7

func Complex64p(key string, val *complex64) zap.Field

Complex64p constructs a field that carries a *complex64. The returned Field will safely and explicitly represent `nil` when appropriate.

func DPanic added in v1.1.4

func DPanic(msg string, fields ...zap.Field)

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.

func Debug

func Debug(msg string, fields ...zap.Field)

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.

func Duration added in v1.1.7

func Duration(key string, val time.Duration) zap.Field

Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.

func Durationp added in v1.1.7

func Durationp(key string, val *time.Duration) zap.Field

Durationp constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.

func Err

func Err(err error) zap.Field

Err is shorthand for the common idiom NamedError("error", err).

func Error

func Error(msg string, fields ...zap.Field)

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.

func ErrorWithCaller

func ErrorWithCaller(msg string, caller zap.Field, fields ...zap.Field)

ErrorWithCaller 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 Errors added in v1.1.3

func Errors(msg string, err error)

Errors 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 Float32 added in v1.1.7

func Float32(key string, val float32) zap.Field

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 Float32p added in v1.1.7

func Float32p(key string, val *float32) zap.Field

Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float64 added in v1.1.7

func Float64(key string, val float64) zap.Field

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 Float64p added in v1.1.7

func Float64p(key string, val *float64) zap.Field

Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Info

func Info(msg string, fields ...zap.Field)

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.

func Int added in v1.1.7

func Int(key string, val int) zap.Field

Int constructs a field with the given key and value.

func Int16 added in v1.1.7

func Int16(key string, val int16) zap.Field

Int16 constructs a field with the given key and value.

func Int16p added in v1.1.7

func Int16p(key string, val *int16) zap.Field

Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int32 added in v1.1.7

func Int32(key string, val int32) zap.Field

Int32 constructs a field with the given key and value.

func Int32p added in v1.1.7

func Int32p(key string, val *int32) zap.Field

Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int64 added in v1.1.7

func Int64(key string, val int64) zap.Field

Int64 constructs a field with the given key and value.

func Int64p added in v1.1.7

func Int64p(key string, val *int64) zap.Field

Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int8 added in v1.1.7

func Int8(key string, val int8) zap.Field

Int8 constructs a field with the given key and value.

func Int8p added in v1.1.7

func Int8p(key string, val *int8) zap.Field

Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Intp added in v1.1.7

func Intp(key string, val *int) zap.Field

Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.

func NamedError added in v1.1.7

func NamedError(key string, err error) zap.Field

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 added in v1.1.7

func Namespace(key string) zap.Field

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 added in v1.1.7

func Object(key string, val zapcore.ObjectMarshaler) zap.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 Panic added in v1.1.4

func Panic(msg string, fields ...zap.Field)

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 panics, even if logging at PanicLevel is disabled.

func Reflect added in v1.1.7

func Reflect(key string, val interface{}) zap.Field

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 added in v1.1.7

func Skip() zap.Field

Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.

func Stack added in v1.1.7

func Stack(key string) zap.Field

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 String added in v1.1.7

func String(key string, val string) zap.Field

String constructs a field with the given key and value.

func Stringer added in v1.1.7

func Stringer(key string, val fmt.Stringer) zap.Field

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 Stringp added in v1.1.7

func Stringp(key string, val *string) zap.Field

Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.

func Sync

func Sync()

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Time added in v1.1.7

func Time(key string, val time.Time) zap.Field

Time constructs a Field with the given key and value. The encoder controls how the time is serialized.

func Timep added in v1.1.7

func Timep(key string, val *time.Time) zap.Field

Timep constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint added in v1.1.7

func Uint(key string, val uint) zap.Field

Uint constructs a field with the given key and value.

func Uint16 added in v1.1.7

func Uint16(key string, val uint16) zap.Field

Uint16 constructs a field with the given key and value.

func Uint16p added in v1.1.7

func Uint16p(key string, val *uint16) zap.Field

Uint16p constructs a field that carries a *uint16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint32 added in v1.1.7

func Uint32(key string, val uint32) zap.Field

Uint32 constructs a field with the given key and value.

func Uint32p added in v1.1.7

func Uint32p(key string, val *uint32) zap.Field

Uint32p constructs a field that carries a *uint32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint64 added in v1.1.7

func Uint64(key string, val uint64) zap.Field

Uint64 constructs a field with the given key and value.

func Uint64p added in v1.1.7

func Uint64p(key string, val *uint64) zap.Field

Uint64p constructs a field that carries a *uint64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint8 added in v1.1.7

func Uint8(key string, val uint8) zap.Field

Uint8 constructs a field with the given key and value.

func Uint8p added in v1.1.7

func Uint8p(key string, val *uint8) zap.Field

Uint8p constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uintp added in v1.1.7

func Uintp(key string, val *uint) zap.Field

Uintp constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uintptr added in v1.1.7

func Uintptr(key string, val uintptr) zap.Field

Uintptr constructs a field with the given key and value.

func Uintptrp added in v1.1.7

func Uintptrp(key string, val *uintptr) zap.Field

Uintptrp constructs a field that carries a *uintptr. The returned Field will safely and explicitly represent `nil` when appropriate.

func Warn added in v1.1.4

func Warn(msg string, fields ...zap.Field)

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.

Types

type Conf added in v1.1.4

type Conf struct {
	OutPath    string `json:"outPath"`
	Level      string `json:"level"`
	MaxSize    int    `json:"maxSize"`
	MaxBackups int    `json:"maxBackups"`
	MaxAge     int    `json:"maxAge"`
	Debug      bool   `json:"debug"`
	LogSelect  bool   `json:"logSelect"`
	Stdout     bool   `json:"-"`
}

Conf log config

type GormLog added in v1.1.7

type GormLog struct {
}

GormLog Gorm loger

func Gorm added in v1.1.7

func Gorm() *GormLog

Gorm Gorm logger object

func (*GormLog) Print added in v1.1.7

func (*GormLog) Print(v ...interface{})

Print Gorm log

type Log added in v1.1.7

type Log struct {
	zap.Logger
	// contains filtered or unexported fields
}

Log log

func Default added in v1.1.7

func Default() *Log

Default rew logger object

func Init added in v1.1.4

func Init(conf *Conf) *Log

Init init log

func New added in v1.1.7

func New(conf *Conf) *Log

New rew logger object

func (*Log) DPanic added in v1.1.7

func (l *Log) DPanic(msg string, fields ...zap.Field)

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.

func (*Log) Debug added in v1.1.7

func (l *Log) Debug(msg string, fields ...zap.Field)

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.

func (*Log) Error added in v1.1.7

func (l *Log) Error(msg string, fields ...zap.Field)

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.

func (*Log) ErrorWithCaller added in v1.1.7

func (l *Log) ErrorWithCaller(msg string, caller zap.Field, fields ...zap.Field)

ErrorWithCaller 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 (*Log) Errors added in v1.1.7

func (l *Log) Errors(msg string, err error)

Errors 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 (*Log) Info added in v1.1.7

func (l *Log) Info(msg string, fields ...zap.Field)

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.

func (*Log) Panic added in v1.1.7

func (l *Log) Panic(msg string, fields ...zap.Field)

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 panics, even if logging at PanicLevel is disabled.

func (*Log) Sync added in v1.1.7

func (l *Log) Sync()

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func (*Log) Warn added in v1.1.7

func (l *Log) Warn(msg string, fields ...zap.Field)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL