zap

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 18 Imported by: 1,184

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Any         = zap.Any
	Array       = zap.Array
	Binary      = zap.Binary
	Bool        = zap.Bool
	Bools       = zap.Bools
	ByteString  = zap.ByteString
	ByteStrings = zap.ByteStrings
	Complex64   = zap.Complex64
	Complex64s  = zap.Complex64s
	Complex128  = zap.Complex128
	Complex128s = zap.Complex128s
	Duration    = zap.Duration
	Durations   = zap.Durations
	Error       = zap.Error
	Errors      = zap.Errors
	Float32     = zap.Float32
	Float32s    = zap.Float32s
	Float64     = zap.Float64
	Float64s    = zap.Float64s
	Int         = zap.Int
	Ints        = zap.Ints
	Int8        = zap.Int8
	Int8s       = zap.Int8s
	Int16       = zap.Int16
	Int16s      = zap.Int16s
	Int32       = zap.Int32
	Int32s      = zap.Int32s
	Int64       = zap.Int64
	Int64s      = zap.Int64s
	Namespace   = zap.Namespace
	Reflect     = zap.Reflect
	Stack       = zap.Stack
	String      = zap.String
	Stringer    = zap.Stringer
	Strings     = zap.Strings
	Time        = zap.Time
	Times       = zap.Times
	Uint        = zap.Uint
	Uints       = zap.Uints
	Uint8       = zap.Uint8
	Uint8s      = zap.Uint8s
	Uint16      = zap.Uint16
	Uint16s     = zap.Uint16s
	Uint32      = zap.Uint32
	Uint32s     = zap.Uint32s
	Uint64      = zap.Uint64
	Uint64s     = zap.Uint64s
	Uintptr     = zap.Uintptr
	Uintptrs    = zap.Uintptrs
)

Field types for structured logging. Most fields are lazily marshaled so it is inexpensive to add fields to disabled log statements.

Functions

func Configure

func Configure(cfg Config) error

Configure configures the logp package.

func DevelopmentSetup

func DevelopmentSetup(options ...Option) error

DevelopmentSetup configures the logger in development mode at debug level. By default the output goes to stderr.

func HasSelector

func HasSelector(selector string) bool

HasSelector returns true if the given selector was explicitly set.

func IsDebug

func IsDebug(selector string) bool

IsDebug returns true if the given selector would be logged. Deprecated: Use logp.NewLogger.

func ObserverLogs

func ObserverLogs() *observer.ObservedLogs

ObserverLogs provides the list of logs generated during the observation process.

func SetLevel added in v0.2.3

func SetLevel(lv Level)

SetLevel 动态设置日志等级

func Sync

func Sync() error

Sync flushes any buffered log entries. Applications should take care to call Sync before exiting.

func TestingSetup

func TestingSetup(options ...Option) error

TestingSetup configures logging by calling DevelopmentSetup if and only if verbose testing is enabled (as in 'go test -v').

Types

type Config

type Config struct {
	Name      string      // Name of the Logger (for default file name).
	JSON      bool        // Write logs as JSON.
	Level     Level       // Logging level (error, warning, info, debug).
	Metas     []zap.Field // Root Logger Metas
	Selectors []string    // Selectors for debug level logging.

	ToStderr   bool
	ToSyslog   bool
	ToFiles    bool
	ToEventLog bool

	Files FileConfig
	// contains filtered or unexported fields
}

Config contains the configuration options for the logger. To create a Config from a common.Config use logp/config.Build.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default config options.

type FileConfig

type FileConfig struct {
	Path            string
	Name            string
	MaxSize         uint
	MaxBackups      uint
	Permissions     uint32
	Interval        time.Duration
	RotateOnStartup bool
	RedirectStderr  bool
}

FileConfig contains the configuration options for the file output.

type Level

type Level int8

Level is a logging priority. Higher levels are more important.

const (
	DebugLevel Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel
	FatalLevel
)

Logging levels.

func NewLevel

func NewLevel(str string) (Level, error)

NewLevel 更加string生成Level

func (Level) Enabled

func (l Level) Enabled(level Level) bool

Enabled returns true if given level is enabled.

func (Level) String

func (l Level) String() string

String returns the name of the logging level.

func (*Level) Unpack

func (l *Level) Unpack(str string) error

Unpack unmarshals a level string to a Level. This implements ucfg.StringUnpacker.

type LogOption

type LogOption = zap.Option

LogOption configures a Logger.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger logs messages to the configured output.

func L

func L() *Logger

L returns an unnamed global logger.

func NewLogger

func NewLogger(selector string, options ...LogOption) *Logger

NewLogger returns a new Logger labeled with the name of the selector. This should never be used from any global contexts, otherwise you will receive a no-op Logger. This is because the logp package needs to be initialized first. Instead create new Logger instance that your object reuses. Or if you need to log from a static context then you may use logp.L().Infow(), for example.

func (*Logger) DPanic

func (l *Logger) DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics.

func (*Logger) DPanicf

func (l *Logger) DPanicf(format string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics.

func (*Logger) DPanicw

func (l *Logger) DPanicw(msg string, fields ...logger.Field)

DPanicw logs a message with some additional context. The logger panics only in Development mode. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf uses fmt.Sprintf to construct and log a message.

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, fields ...logger.Field)

Debugw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, fields ...logger.Field)

Errorw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit(1).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit(1).

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, fields ...logger.Field)

Fatalw logs a message with some additional context, then calls os.Exit(1). The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func (*Logger) Infow

func (l *Logger) Infow(msg string, fields ...logger.Field)

Infow logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) IsDebug

func (l *Logger) IsDebug() bool

IsDebug checks to see if the given logger is Debug enabled.

func (*Logger) Named

func (l *Logger) Named(name string) logger.Logger

Named adds a new path segment to the logger's name. Segments are joined by periods.

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*Logger) Panicw

func (l *Logger) Panicw(msg string, fields ...logger.Field)

Panicw logs a message with some additional context, then panics. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) Print added in v0.3.4

func (l *Logger) Print(args ...interface{})

Print uses fmt.Sprint to construct and log a message.

func (*Logger) Printf added in v0.3.4

func (l *Logger) Printf(format string, args ...interface{})

Printf todo

func (*Logger) Println added in v0.3.4

func (l *Logger) Println(args ...interface{})

Println todo

func (*Logger) Recover

func (l *Logger) Recover(msg string)

Recover stops a panicking goroutine and logs an Error.

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, fields ...logger.Field)

Warnw logs a message with some additional context. The additional context is added in the form of key-value pairs. The optimal way to write the value to the log message will be inferred by the value's type. To explicitly specify a type you can pass a Field such as logp.Stringer.

func (*Logger) With

func (l *Logger) With(fields ...logger.Field) logger.Logger

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 (*Logger) WithNamespace

func (l *Logger) WithNamespace(namespace string) *Logger

WithNamespace todo

type Meta

type Meta = map[string]interface{}

Meta 日志meta数据

type Option

type Option func(cfg *Config)

Option configures the logp package behavior.

func AsJSON

func AsJSON() Option

AsJSON specifies to log the output as JSON.

func ToDiscardOutput

func ToDiscardOutput() Option

ToDiscardOutput configures the logger to write to io.Discard. This is for benchmarking purposes only.

func ToObserverOutput

func ToObserverOutput() Option

ToObserverOutput specifies that the output should be collected in memory so that they can be read by an observer by calling ObserverLogs().

func WithLevel

func WithLevel(level Level) Option

WithLevel specifies the logging level.

func WithSelectors

func WithSelectors(selectors ...string) Option

WithSelectors specifies what debug selectors are enabled. If no selectors are specified then they are all enabled.

Jump to

Keyboard shortcuts

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