Documentation ¶
Index ¶
- Constants
- func Array(key string, val zapcore.ArrayMarshaler) zapcore.Field
- func Bools(key string, bs []bool) zapcore.Field
- func ByteStrings(key string, bss [][]byte) zapcore.Field
- func CheckErr(err error, logFunc func(string, ...interface{})) (isErr bool)
- func Complex128s(key string, nums []complex128) zapcore.Field
- func Complex64s(key string, nums []complex64) zapcore.Field
- func Debug(msg string, args ...interface{})
- func Debugf(format string, args ...interface{})
- func DefaultDir() string
- func Durations(key string, ds []time.Duration) zapcore.Field
- func Error(msg string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errors(key string, errs []error) zapcore.Field
- func Fatal(msg string, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Float32s(key string, nums []float32) zapcore.Field
- func Float64s(key string, nums []float64) zapcore.Field
- func Info(msg string, args ...interface{})
- func Infof(format string, args ...interface{})
- func Int16s(key string, nums []int16) zapcore.Field
- func Int32s(key string, nums []int32) zapcore.Field
- func Int64s(key string, nums []int64) zapcore.Field
- func Int8s(key string, nums []int8) zapcore.Field
- func Ints(key string, nums []int) zapcore.Field
- func Panic(msg string, args ...interface{})
- func Panicf(format string, args ...interface{})
- func Register(name string, logger *Logger)
- func SetDefaultDir(dir string)
- func SetDefaultFields(fs ...Field)
- func SetDefaultFileSuffix(suffix string)
- func SetDefaultLogger(l *Logger)
- func Strings(key string, ss []string) zapcore.Field
- func Sync()
- func Times(key string, ts []time.Time) zapcore.Field
- func Uint16s(key string, nums []uint16) zapcore.Field
- func Uint32s(key string, nums []uint32) zapcore.Field
- func Uint64s(key string, nums []uint64) zapcore.Field
- func Uint8s(key string, nums []uint8) zapcore.Field
- func Uintptrs(key string, us []uintptr) zapcore.Field
- func Uints(key string, nums []uint) zapcore.Field
- func WDebug(log string, msg string, args ...interface{})
- func WDebugf(log string, format string, args ...interface{})
- func WError(log, msg string, args ...interface{})
- func WErrorf(log, format string, args ...interface{})
- func WFatal(log, msg string, args ...interface{})
- func WFatalf(log, format string, args ...interface{})
- func WInfo(log string, msg string, args ...interface{})
- func WInfof(log string, format string, args ...interface{})
- func WPanic(log, msg string, args ...interface{})
- func WPanicf(log, format string, args ...interface{})
- func WWarn(log string, msg string, args ...interface{})
- func WWarnf(log string, format string, args ...interface{})
- func Warn(msg string, args ...interface{})
- func Warnf(format string, args ...interface{})
- type ConsoleWriter
- func (writer *ConsoleWriter) CheckErr(err error, logFunc func(string, ...interface{})) (isErr bool)
- func (writer *ConsoleWriter) Close() error
- func (writer *ConsoleWriter) Level() int
- func (writer *ConsoleWriter) Print(level int, msg string, keysAndValues ...interface{})
- func (writer *ConsoleWriter) Printf(level int, format string, keysAndValues ...interface{})
- func (writer *ConsoleWriter) SetAsync(async bool)
- func (writer *ConsoleWriter) SetPattern(pattern string)
- func (writer *ConsoleWriter) SetPrefix(prefix string)
- func (writer *ConsoleWriter) Start()
- func (writer *ConsoleWriter) Sync() error
- func (writer *ConsoleWriter) Write(str []byte) (n int, err error)
- type Field
- func Any(key string, value interface{}) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func ByteString(key string, val []byte) Field
- func Complex128(key string, val complex128) Field
- func Complex64(key string, val complex64) Field
- func DefaultFields() []Field
- func Duration(key string, val time.Duration) Field
- func Err(err error) Field
- func Float32(key string, val float32) Field
- func Float64(key string, val float64) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int32(key string, val int32) Field
- func Int64(key string, val int64) Field
- func Int8(key string, val int8) Field
- func NamedErr(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 String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Time(key string, val time.Time) Field
- func Uint(key string, val uint) Field
- func Uint16(key string, val uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint8(key string, val uint8) Field
- func Uintptr(key string, val uintptr) Field
- type Logger
- func (l *Logger) CheckErr(err error, logFunc func(string, ...interface{})) (isErr bool)
- func (l *Logger) Debug(msg string, args ...interface{})
- func (l Logger) Debugf(format string, args ...interface{})
- func (l Logger) Error(msg string, args ...interface{})
- func (l Logger) Errorf(format string, args ...interface{})
- func (l Logger) Fatal(msg string, args ...interface{})
- func (l Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(msg string, args ...interface{})
- func (l Logger) Infof(format string, args ...interface{})
- func (l Logger) Panic(msg string, args ...interface{})
- func (l Logger) Panicf(format string, args ...interface{})
- func (l *Logger) Print(level int, msg string, args ...interface{})
- func (l *Logger) Printf(level int, format string, args ...interface{})
- func (l Logger) Sync()
- func (l Logger) Warn(msg string, args ...interface{})
- func (l Logger) Warnf(format string, args ...interface{})
- type Option
- func WithAsync(async bool) Option
- func WithColorful(colorful bool) Option
- func WithFields(fs ...zapcore.Field) Option
- func WithLevel(lvFn func(string, ...interface{})) Option
- func WithLevelCombo(combo string) Option
- func WithLevelMask(lvMask int) Option
- func WithLevelString(combinedLv string) Option
- func WithName(name string) Option
- func WithOutput(opts ...Option) Option
- func WithOutputKV(kv map[string]interface{}) Option
- func WithOutputKVs(kvs []interface{}) Option
- func WithPath(path string) Option
- func WithPrefix(prefix string) Option
- type Options
- type Writer
- type ZapWriter
- func (l *ZapWriter) CheckErr(err error, logFunc func(string, ...interface{})) (isErr bool)
- func (l *ZapWriter) Level() int
- func (l *ZapWriter) Print(level int, msg string, keysAndValues ...interface{})
- func (l *ZapWriter) Printf(level int, format string, keysAndValues ...interface{})
- func (l *ZapWriter) Sync() error
Constants ¶
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel = 1 << iota // InfoLevel is the default logging priority. InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-Level logs. ErrorLevel // PanicLevel logs a message, then panics. PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel )
A Level is a logging priority. Higher levels are more important.
const (
ConsoleQueueLength = 1024 * 1024 * 10
)
Variables ¶
This section is empty.
Functions ¶
func Array ¶
func Array(key string, val zapcore.ArrayMarshaler) zapcore.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 ByteStrings ¶
ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.
func Complex128s ¶
func Complex128s(key string, nums []complex128) zapcore.Field
Complex128s constructs a field that carries a slice of complex numbers.
func Complex64s ¶
Complex64s constructs a field that carries a slice of complex numbers.
func Debug ¶
func Debug(msg string, args ...interface{})
Debug logs debug level messages with default logger.
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs debug level messages with default logger in printf-style.
func Error ¶
func Error(msg string, args ...interface{})
Error logs Error level messages with default logger in structured-style. Notice: additional stack will be added into messages.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs Error level messages with default logger in printf-style. Notice: additional stack will be added into messages.
func Fatal ¶
func Fatal(msg string, args ...interface{})
Fatal logs Fatal level messages with default logger in structured-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs Fatalf level messages with default logger in printf-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func Info ¶
func Info(msg string, args ...interface{})
Info logs Info level messages with default logger in structured-style.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs Info level messages with default logger in printf-style.
func Panic ¶
func Panic(msg string, args ...interface{})
Panic logs Panic level messages with default logger in structured-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf logs Panicf level messages with default logger in printf-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
func SetDefaultDir ¶
func SetDefaultDir(dir string)
SetDefaultDir sets default directory of all zap writer logger.
func SetDefaultFields ¶
func SetDefaultFields(fs ...Field)
SetDefaultFields sets default fields of all logger.
func SetDefaultFileSuffix ¶
func SetDefaultFileSuffix(suffix string)
SetDefaultFileSuffix sets default file suffix.
func SetDefaultLogger ¶
func SetDefaultLogger(l *Logger)
SetDefaultLogger sets default logger with provided logger. Deprecated: use welfare API instead.
func WError ¶
func WError(log, msg string, args ...interface{})
WError logs Error level messages with default logger in structured-style. Notice: additional stack will be added into messages.
func WErrorf ¶
func WErrorf(log, format string, args ...interface{})
WErrorf logs Error level messages with default logger in printf-style. Notice: additional stack will be added into messages.
func WFatal ¶
func WFatal(log, msg string, args ...interface{})
WFatal logs Fatal level messages with default logger in structured-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func WFatalf ¶
func WFatalf(log, format string, args ...interface{})
WFatalf logs Fatalf level messages with default logger in printf-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func WPanic ¶
func WPanic(log, msg string, args ...interface{})
WPanic logs Panic level messages with default logger in structured-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
func WPanicf ¶
func WPanicf(log, format string, args ...interface{})
WPanicf logs Panicf level messages with default logger in printf-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
Types ¶
type ConsoleWriter ¶
type ConsoleWriter struct {
// contains filtered or unexported fields
}
ConsoleWriter will print logger mesgaes into console
func NewConsoleWriter ¶
func NewConsoleWriter(lv int, colorful bool, fs []Field) *ConsoleWriter
NewConsoleWriter constructs a new ConsoleWriter instance.
func (*ConsoleWriter) CheckErr ¶
func (writer *ConsoleWriter) CheckErr(err error, logFunc func(string, ...interface{})) (isErr bool)
CheckErr checks error, error will be logged if it's not equal to nil.
func (*ConsoleWriter) Level ¶
func (writer *ConsoleWriter) Level() int
Level return ConsoleWriter's level.
func (*ConsoleWriter) Print ¶
func (writer *ConsoleWriter) Print(level int, msg string, keysAndValues ...interface{})
Print implements Writer Print method.
func (*ConsoleWriter) Printf ¶
func (writer *ConsoleWriter) Printf(level int, format string, keysAndValues ...interface{})
Printf implements Writer Printf method.
func (*ConsoleWriter) SetAsync ¶
func (writer *ConsoleWriter) SetAsync(async bool)
SetAsync sets async trigger.
func (*ConsoleWriter) SetPattern ¶
func (writer *ConsoleWriter) SetPattern(pattern string)
SetPattern sets pattern.
func (*ConsoleWriter) SetPrefix ¶
func (writer *ConsoleWriter) SetPrefix(prefix string)
SetPrefix sets prefix.
func (*ConsoleWriter) Sync ¶
func (writer *ConsoleWriter) Sync() error
Sync flushes any buffered log entries.
type Field ¶
A Field is a marshaling operation used to add a key-value pair to a logger's context. Most fields are lazily marshaled, so it's inexpensive to add fields to disabled debug-level log statements.
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 suprise, []byte values are treated as binary blobs, byte values are treated as uint8, and runes are always treated as integers.
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 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 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 Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
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 NamedErr ¶
NamedErr 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 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 zapcore.Field with the given key and value. The encoder controls how the time is serialized.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an interface supports printf-style and structured-style logging.
func (Logger) Error ¶
Error logs Error level messages in structured-style. Notice: additional stack will be added into messages.
func (Logger) Errorf ¶
Errorf logs Error level messages in printf-style. Notice: additional stack will be added into messages.
func (Logger) Fatal ¶
Fatal logs Fatal level messages in structured-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func (Logger) Fatalf ¶
Fatalf logs Fatalf level messages in printf-style. Notice: additional stack will be added into messages, then calls os.Exit(1).
func (Logger) Panic ¶
Panic logs Panic level messages in structured-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
func (Logger) Panicf ¶
Panicf logs Panicf level messages in printf-style. Notice: additional stack will be added into messages, meanwhile logger will panic.
type Option ¶
type Option func(*Options)
Option is used to set options for the logger.
func WithColorful ¶
WithColorful configures the console-log's colorful trigger.
func WithLevelCombo ¶
WithLevelCombo configures the Logger enabled levels with level combos. ex. "Warn | Error | Panic | Fatal" will enable Warn, Error, Panic and Fatal level logging.
func WithLevelMask ¶
WithLevelMask configures logger enabled levels with level masks.
func WithLevelString ¶
WithLevelString configures the Logger enabled levels with combined level string. ex. "Warn | Error | Panic | Fatal" will enable Warn, Error, Panic and Fatal level logging. Deprecated: use WithLevelCombo instead.
func WithOutput ¶
WithOutput adds log a new writer with options.
func WithOutputKV ¶
WithOutputKV adds logger a new writer with KV.
func WithOutputKVs ¶
func WithOutputKVs(kvs []interface{}) Option
WithOutputKVs adds logger a new writer with KVs.
func WithPrefix ¶
WithPrefix configures the console-log's prefix.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options wraps logger options.
type Writer ¶
type Writer interface { Sync() error Level() int Print(int, string, ...interface{}) Printf(int, string, ...interface{}) CheckErr(error, func(string, ...interface{})) bool }
Writer defines logger's writer.
type ZapWriter ¶
type ZapWriter struct {
// contains filtered or unexported fields
}
A ZapWriter wraps the zap.SugarWriter.
func NewZapWriter ¶
NewZapWriter constructs a new ZapWriter instance.