log

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 17 Imported by: 3

Documentation

Overview

Package log micserver 中使用的 log 系统,支持 Syslog(系统信息)/Debug(调试)/Info(关心的)/ Warning(警告)/Error(错误)/Fatal(致命) 日志级别,日志可按大小/小时转储。 建议: 系统运行的各个细节/详细步骤使用 Syslog 级别记录,为了减小 log 系统造成的运算负担, 应该先使用 IsSyslogEnable() 判断 Syslog 级别的日志是否开启,再调用 Syslog() 记录; 业务的主要环节/关键节点的调试使用 Debug 级别记录; 业务造成的结果,或需要在后续运营维护中查看用户信息变更,使用 Info 级别记录; 客户端/用户的输入错误,或者系统设计意外的条件不满足,使用 Warning 级别记录; 该分布式系统内部的错误值(与客户端等无关),但是可以恢复或者对业务逻辑没有影响时, 使用 Error 级别记录; 在 Error 级别的基础上,如果错误无法代码恢复或者对业务逻辑产生必要影响时,使用 Fatal 级别记录。 在生产环境/正式环境中,应该将日志等级至高调整至 Info ,在需要必要的调试信息时, 可调整至 Debug 。不要在正式环境中启用 Syslog 日志等级,你只应该在开发环境中使用它。 Warning / Error / Fatal 日志级别,无论何时你都要谨慎关闭他们,如果你确定不关心 你业务的信息,可以调整至 Warning 级别,但是无论如何,关闭警告或者错误都是一个极具风险 的决定。

Index

Constants

View Source
const (
	// SysLevel logs are typically voluminous, and are usually disabled in
	// production.
	SysLevel = core.SysLevel
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = core.DebugLevel
	// InfoLevel is the default logging priority.
	InfoLevel = core.InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = core.WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = core.ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = core.DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel = core.PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = core.FatalLevel
)

Variables

View Source
var (
	ErrNilLogger       = errors.New("logger is nil")
	ErrUnknownLogLevel = errors.New("unknown log level")
)

error

Functions

func DPanic added in v0.1.1

func DPanic(fmt string, args ...interface{})

DPanic 默认 Logger 异步输出一条 DPanic 级别的日志

func Debug

func Debug(fmt string, args ...interface{})

Debug 默认 Logger 异步输出一条 Debug 级别的日志

func Error

func Error(fmt string, args ...interface{})

Error 默认 Logger 异步输出一条 Error 级别的日志

func Fatal

func Fatal(fmt string, args ...interface{})

Fatal 默认 Logger 异步输出一条 Fatal 级别的日志

func Info

func Info(fmt string, args ...interface{})

Info 默认 Logger 异步输出一条 Info 级别的日志

func IsDPanicEnable added in v0.1.1

func IsDPanicEnable() bool

IsDPanicEnable 默认 Logger 判断 DPanic 日志级别是否开启

func IsDebugEnable

func IsDebugEnable() bool

IsDebugEnable 默认 Logger 判断 Debug 日志级别是否开启

func IsErrorEnable

func IsErrorEnable() bool

IsErrorEnable 默认 Logger 判断 Error 日志级别是否开启

func IsFatalEnable

func IsFatalEnable() bool

IsFatalEnable 默认 Logger 判断 Fatal 日志级别是否开启

func IsInfoEnable

func IsInfoEnable() bool

IsInfoEnable 默认 Logger 判断 Warn 日志级别是否开启

func IsPanicEnable added in v0.1.1

func IsPanicEnable() bool

IsPanicEnable 默认 Logger 判断 Panic 日志级别是否开启

func IsSyslogEnable

func IsSyslogEnable() bool

IsSyslogEnable 默认 Logger 判断 Syslog 日志级别是否开启

func IsWarnEnable

func IsWarnEnable() bool

IsWarnEnable 默认 Logger 判断 Info 日志级别是否开启

func Panic added in v0.1.1

func Panic(fmt string, args ...interface{})

Panic 默认 Logger 异步输出一条 Panic 级别的日志

func SetDefaultLogger

func SetDefaultLogger(l *Logger)

SetDefaultLogger 设置默认 Logger

func SetLogLevel

func SetLogLevel(lvl Level)

SetLogLevel 默认 Logger 设置日志等级

func SetLogLevelByStr

func SetLogLevelByStr(lvl string) error

SetLogLevelByStr 默认 Logger 使用等级名设置日志等级

func Syslog

func Syslog(fmt string, args ...interface{})

Syslog 默认 Logger 异步输出一条 Syslog 级别的日志

func Warn

func Warn(fmt string, args ...interface{})

Warn 默认 Logger 异步输出一条 Warn 级别的日志

Types

type AtomicLevel added in v0.1.1

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

An AtomicLevel is an atomically changeable, dynamic logging level. It lets you safely change the log level of a tree of loggers (the root logger and any children created by adding context) at runtime.

The AtomicLevel itself is an http.Handler that serves a JSON endpoint to alter its level.

AtomicLevels must be created with the NewAtomicLevel constructor to allocate their internal atomic pointer.

func NewAtomicLevel added in v0.1.1

func NewAtomicLevel() AtomicLevel

NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging enabled.

func NewAtomicLevelAt added in v0.1.1

func NewAtomicLevelAt(l core.Level) AtomicLevel

NewAtomicLevelAt is a convenience function that creates an AtomicLevel and then calls SetLevel with the given level.

func (AtomicLevel) Enabled added in v0.1.1

func (lvl AtomicLevel) Enabled(l core.Level) bool

Enabled implements the core.LevelEnabler interface, which allows the AtomicLevel to be used in place of traditional static levels.

func (AtomicLevel) Level added in v0.1.1

func (lvl AtomicLevel) Level() core.Level

Level returns the minimum enabled log level.

func (AtomicLevel) MarshalText added in v0.1.1

func (lvl AtomicLevel) MarshalText() (text []byte, err error)

MarshalText marshals the AtomicLevel to a byte slice. It uses the same text representation as the static core.Levels ("debug", "info", "warn", "error", "dpanic", "panic", and "fatal").

func (AtomicLevel) SetLevel added in v0.1.1

func (lvl AtomicLevel) SetLevel(l core.Level)

SetLevel alters the logging level.

func (AtomicLevel) String added in v0.1.1

func (lvl AtomicLevel) String() string

String returns the string representation of the underlying Level.

func (*AtomicLevel) UnmarshalText added in v0.1.1

func (lvl *AtomicLevel) UnmarshalText(text []byte) error

UnmarshalText unmarshals the text to an AtomicLevel. It uses the same text representations as the static core.Levels ("debug", "info", "warn", "error", "dpanic", "panic", and "fatal").

type Field added in v0.1.1

type Field = core.Field

Field is an alias for Field. Aliasing this type dramatically improves the navigability of this package's API documentation.

func Any added in v0.1.1

func Any(key string, value interface{}) 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 Array added in v0.1.1

func Array(key string, val core.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 added in v0.1.1

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

Binary constructs a field that carries an opaque binary blob.

Binary data is serialized in an encoding-appropriate format. For example, core's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.

func Bool added in v0.1.1

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func Boolp added in v0.1.1

func Boolp(key string, val *bool) Field

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

func Bools added in v0.1.1

func Bools(key string, bs []bool) Field

Bools constructs a field that carries a slice of bools.

func ByteString added in v0.1.1

func ByteString(key string, val []byte) 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 ByteStrings added in v0.1.1

func ByteStrings(key string, bss [][]byte) Field

ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.

func Complex128 added in v0.1.1

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 Complex128p added in v0.1.1

func Complex128p(key string, val *complex128) Field

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

func Complex128s added in v0.1.1

func Complex128s(key string, nums []complex128) Field

Complex128s constructs a field that carries a slice of complex numbers.

func Complex64 added in v0.1.1

func Complex64(key string, val complex64) 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 v0.1.1

func Complex64p(key string, val *complex64) Field

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

func Complex64s added in v0.1.1

func Complex64s(key string, nums []complex64) Field

Complex64s constructs a field that carries a slice of complex numbers.

func Duration added in v0.1.1

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

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

func Durationp added in v0.1.1

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

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

func Durations added in v0.1.1

func Durations(key string, ds []time.Duration) Field

Durations constructs a field that carries a slice of time.Durations.

func ErrorField added in v0.1.1

func ErrorField(err error) Field

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

func Errors added in v0.1.1

func Errors(key string, errs []error) Field

Errors constructs a field that carries a slice of errors.

func Float32 added in v0.1.1

func Float32(key string, val float32) 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 v0.1.1

func Float32p(key string, val *float32) Field

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

func Float32s added in v0.1.1

func Float32s(key string, nums []float32) Field

Float32s constructs a field that carries a slice of floats.

func Float64 added in v0.1.1

func Float64(key string, val float64) 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 v0.1.1

func Float64p(key string, val *float64) Field

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

func Float64s added in v0.1.1

func Float64s(key string, nums []float64) Field

Float64s constructs a field that carries a slice of floats.

func Int added in v0.1.1

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int16 added in v0.1.1

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16p added in v0.1.1

func Int16p(key string, val *int16) Field

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

func Int16s added in v0.1.1

func Int16s(key string, nums []int16) Field

Int16s constructs a field that carries a slice of integers.

func Int32 added in v0.1.1

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32p added in v0.1.1

func Int32p(key string, val *int32) Field

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

func Int32s added in v0.1.1

func Int32s(key string, nums []int32) Field

Int32s constructs a field that carries a slice of integers.

func Int64 added in v0.1.1

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64p added in v0.1.1

func Int64p(key string, val *int64) Field

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

func Int64s added in v0.1.1

func Int64s(key string, nums []int64) Field

Int64s constructs a field that carries a slice of integers.

func Int8 added in v0.1.1

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8p added in v0.1.1

func Int8p(key string, val *int8) Field

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

func Int8s added in v0.1.1

func Int8s(key string, nums []int8) Field

Int8s constructs a field that carries a slice of integers.

func Intp added in v0.1.1

func Intp(key string, val *int) Field

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

func Ints added in v0.1.1

func Ints(key string, nums []int) Field

Ints constructs a field that carries a slice of integers.

func NamedError added in v0.1.1

func NamedError(key string, err error) 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/liasece/micserver/util/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 v0.1.1

func Namespace(key string) 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 v0.1.1

func Object(key string, val core.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 added in v0.1.1

func Reflect(key string, val interface{}) 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 v0.1.1

func Skip() Field

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

func Stack added in v0.1.1

func Stack(key string) 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 v0.1.1

func String(key string, val string) Field

String constructs a field with the given key and value.

func Stringer added in v0.1.1

func Stringer(key string, val fmt.Stringer) 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 v0.1.1

func Stringp(key string, val *string) Field

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

func Strings added in v0.1.1

func Strings(key string, ss []string) Field

Strings constructs a field that carries a slice of strings.

func Time added in v0.1.1

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

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

func Timep added in v0.1.1

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

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

func Times added in v0.1.1

func Times(key string, ts []time.Time) Field

Times constructs a field that carries a slice of time.Times.

func Uint added in v0.1.1

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint16 added in v0.1.1

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16p added in v0.1.1

func Uint16p(key string, val *uint16) Field

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

func Uint16s added in v0.1.1

func Uint16s(key string, nums []uint16) Field

Uint16s constructs a field that carries a slice of unsigned integers.

func Uint32 added in v0.1.1

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32p added in v0.1.1

func Uint32p(key string, val *uint32) Field

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

func Uint32s added in v0.1.1

func Uint32s(key string, nums []uint32) Field

Uint32s constructs a field that carries a slice of unsigned integers.

func Uint64 added in v0.1.1

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64p added in v0.1.1

func Uint64p(key string, val *uint64) Field

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

func Uint64s added in v0.1.1

func Uint64s(key string, nums []uint64) Field

Uint64s constructs a field that carries a slice of unsigned integers.

func Uint8 added in v0.1.1

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8p added in v0.1.1

func Uint8p(key string, val *uint8) Field

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

func Uint8s added in v0.1.1

func Uint8s(key string, nums []uint8) Field

Uint8s constructs a field that carries a slice of unsigned integers.

func Uintp added in v0.1.1

func Uintp(key string, val *uint) Field

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

func Uintptr added in v0.1.1

func Uintptr(key string, val uintptr) Field

Uintptr constructs a field with the given key and value.

func Uintptrp added in v0.1.1

func Uintptrp(key string, val *uintptr) Field

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

func Uintptrs added in v0.1.1

func Uintptrs(key string, us []uintptr) Field

Uintptrs constructs a field that carries a slice of pointer addresses.

func Uints added in v0.1.1

func Uints(key string, nums []uint) Field

Uints constructs a field that carries a slice of unsigned integers.

type Flusher

type Flusher interface {
	Flush() error
}

Flusher 刷新输出

type ILogger

type ILogger interface {
	Syslog(fmt string, args ...interface{})
	Debug(fmt string, args ...interface{})
	Warn(fmt string, args ...interface{})
	Info(fmt string, args ...interface{})
	Error(fmt string, args ...interface{})
	Fatal(fmt string, args ...interface{})
	IsSyslogEnable() bool
	IsDebugEnable() bool
	IsWarnEnable() bool
	IsInfoEnable() bool
	IsErrorEnable() bool
	IsFatalEnable() bool
	Clone() *Logger
	SetTopic(topic string)
	GetLogLevel() int32
	SetLogName(logname string)
	GetLogger() *Logger
}

ILogger 日志系统实现的接口

type Level

type Level = core.Level

Level are log core level

type LevelEnablerFunc added in v0.1.1

type LevelEnablerFunc func(core.Level) bool

LevelEnablerFunc is a convenient way to implement core.LevelEnabler with an anonymous function.

It's particularly useful when splitting log output between different outputs (e.g., standard error and standard out). For sample code, see the package-level AdvancedConfiguration example.

func (LevelEnablerFunc) Enabled added in v0.1.1

func (f LevelEnablerFunc) Enabled(lvl core.Level) bool

Enabled calls the wrapped function.

type Logger

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

Logger 日志实例

func GetDefaultLogger

func GetDefaultLogger() *Logger

GetDefaultLogger 获取默认 Logger

func NewLogger

func NewLogger(c core.Core, optps ...Option) *Logger

NewLogger 构造一个日志

func (*Logger) Clone

func (l *Logger) Clone() *Logger

Clone 浅拷贝出一个 Logger ,他们具备相同的底层写入接口, 需要注意的是,克隆出来的logger对象在写入器中会依旧受到源拷贝对象的影响

func (*Logger) Debug

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

Debug level log record

func (*Logger) Error

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

Error level log record

func (*Logger) Fatal

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

Fatal level log record

func (*Logger) GetLogger

func (l *Logger) GetLogger() *Logger

GetLogger get current Logger's Logger, mening Logger isn't nil, if nil, will be called defaultLogger to opration, so return defaultLogger.

func (*Logger) Info

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

Info level log record

func (*Logger) IsDPanicEnable added in v0.1.1

func (l *Logger) IsDPanicEnable() bool

IsDPanicEnable 判断 DPanic 日志级别是否开启

func (*Logger) IsDebugEnable

func (l *Logger) IsDebugEnable() bool

IsDebugEnable 判断 Debug 日志级别是否开启

func (*Logger) IsErrorEnable

func (l *Logger) IsErrorEnable() bool

IsErrorEnable 判断 Error 日志级别是否开启

func (*Logger) IsFatalEnable

func (l *Logger) IsFatalEnable() bool

IsFatalEnable 判断 Fatal 日志级别是否开启

func (*Logger) IsInfoEnable

func (l *Logger) IsInfoEnable() bool

IsInfoEnable 判断 Warn 日志级别是否开启

func (*Logger) IsPanicEnable added in v0.1.1

func (l *Logger) IsPanicEnable() bool

IsPanicEnable 判断 Panic 日志级别是否开启

func (*Logger) IsSyslogEnable

func (l *Logger) IsSyslogEnable() bool

IsSyslogEnable 判断 Syslog 日志级别是否开启

func (*Logger) IsWarnEnable

func (l *Logger) IsWarnEnable() bool

IsWarnEnable 判断 Info 日志级别是否开启

func (*Logger) Panic added in v0.1.1

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

Panic level log record

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(lvl Level)

SetLogLevel 设置日志等级

func (*Logger) SetLogLevelByStr

func (l *Logger) SetLogLevelByStr(lvl string) error

SetLogLevelByStr 使用等级名设置日志等级

func (*Logger) SetLogName

func (l *Logger) SetLogName(logname string)

SetLogName 设置日志名称,一般使用进程或者模块名字

func (*Logger) SetTopic

func (l *Logger) SetTopic(topic string) error

SetTopic 设置该日志主题,一般设置为 SetLogName() 的下一级系统名称

func (*Logger) Syslog

func (l *Logger) Syslog(fmt string, args ...interface{})

Syslog level log record

func (*Logger) Warn

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

Warn level log record

func (*Logger) With added in v0.1.1

func (l *Logger) With(fields ...Field) *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.

type Option added in v0.1.1

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

type Record

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

Record 一条日志记录

func (*Record) String

func (r *Record) String() string

String 格式化该日志记录字符串

type Rotater

type Rotater interface {
	Rotate() error
	RotateByTime(*time.Time) error
}

Rotater 转储器实现的接口

type TOptions added in v0.1.1

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

TOptions type of options

func Options

func Options() *TOptions

Options func

func (*TOptions) AddCaller added in v0.1.1

func (o *TOptions) AddCaller() *TOptions

AddCaller configures the Logger to annotate each message with the filename and line number of log's caller. See also WithCaller.

func (*TOptions) AddCallerSkip added in v0.1.1

func (o *TOptions) AddCallerSkip(skip int) *TOptions

AddCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option). When building wrappers around the Logger and SugaredLogger, supplying this Option prevents log from always reporting the wrapper code as the caller.

func (*TOptions) AddStack added in v0.1.1

func (o *TOptions) AddStack(value core.LevelEnabler) *TOptions

AddStack add config to the Logger.

func (*TOptions) AsyncWrite added in v0.1.1

func (o *TOptions) AsyncWrite(value bool) *TOptions

AsyncWrite add config to the Logger.

func (*TOptions) AsyncWriteDuration added in v0.1.1

func (o *TOptions) AsyncWriteDuration(value time.Duration) *TOptions

AsyncWriteDuration add config to the Logger.

func (*TOptions) Development added in v0.1.1

func (o *TOptions) Development() *TOptions

Development puts the logger in development mode, which makes DPanic-level logs panic instead of simply logging an error.

func (*TOptions) ErrorOutput added in v0.1.1

func (o *TOptions) ErrorOutput(value core.WriteSyncer) *TOptions

ErrorOutput add config to the Logger.

func (*TOptions) Fields added in v0.1.1

func (o *TOptions) Fields(fs ...Field) *TOptions

Fields adds fields to the Logger.

func (*TOptions) FilePaths added in v0.1.1

func (o *TOptions) FilePaths(path ...string) *TOptions

FilePaths add config to the Logger.

func (*TOptions) Hooks added in v0.1.1

func (o *TOptions) Hooks(hooks ...func(core.Entry) error) *TOptions

Hooks registers functions which will be called each time the Logger writes out an Entry. Repeated use of Hooks is additive.

Hooks are useful for simple side effects, like capturing metrics for the number of emitted logs. More complex side effects, including anything that requires access to the Entry's structured fields, should be implemented as a core.Core instead. See core.RegisterHooks for details.

func (*TOptions) Level added in v0.1.1

func (o *TOptions) Level(value Level) *TOptions

Level add config to the Logger.

func (*TOptions) Name added in v0.1.1

func (o *TOptions) Name(value string) *TOptions

Name add config to the Logger.

func (*TOptions) NoConsole added in v0.1.1

func (o *TOptions) NoConsole(value bool) *TOptions

NoConsole add config to the Logger.

func (*TOptions) NoConsoleColor added in v0.1.1

func (o *TOptions) NoConsoleColor(value bool) *TOptions

NoConsoleColor add config to the Logger.

func (*TOptions) RecordTimeLayout added in v0.1.1

func (o *TOptions) RecordTimeLayout(value string) *TOptions

RecordTimeLayout add config to the Logger.

func (*TOptions) RedirectError added in v0.1.1

func (o *TOptions) RedirectError(value bool) *TOptions

RedirectError add config to the Logger.

func (*TOptions) RotateTimeLayout added in v0.1.1

func (o *TOptions) RotateTimeLayout(value string) *TOptions

RotateTimeLayout add config to the Logger.

func (*TOptions) Topic added in v0.1.1

func (o *TOptions) Topic(value string) *TOptions

Topic add config to the Logger.

func (*TOptions) WithCaller added in v0.1.1

func (o *TOptions) WithCaller(enabled bool) *TOptions

WithCaller configures the Logger to annotate each message with the filename and line number of log's caller, or not, depending on the value of enabled. This is a generalized form of AddCaller.

func (*TOptions) WrapCore added in v0.1.1

func (o *TOptions) WrapCore(f func(core.Core) core.Core) *TOptions

WrapCore wraps or replaces the Logger's underlying core.Core.

type Writer

type Writer interface {
	Write(*Record) error
}

Writer 输出器实现的接口

Directories

Path Synopsis
Package buffer provides a thin wrapper around a byte slice.
Package buffer provides a thin wrapper around a byte slice.
Package core defines and implements the low-level interfaces upon which core is built.
Package core defines and implements the low-level interfaces upon which core is built.
internal
bufferpool
Package bufferpool houses core's shared internal buffer pool.
Package bufferpool houses core's shared internal buffer pool.
color
Package color adds coloring functionality for TTY output.
Package color adds coloring functionality for TTY output.
exit
Package exit provides stubs so that unit tests can exercise code that calls os.Exit(1).
Package exit provides stubs so that unit tests can exercise code that calls os.Exit(1).
ztest
Package ztest provides low-level helpers for testing log output.
Package ztest provides low-level helpers for testing log output.
Package test provides a variety of helpers for testing log output.
Package test provides a variety of helpers for testing log output.
observer
Package observer provides a core.Core that keeps an in-memory, encoding-agnostic repesentation of log entries.
Package observer provides a core.Core that keeps an in-memory, encoding-agnostic repesentation of log entries.

Jump to

Keyboard shortcuts

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