Documentation
¶
Overview ¶
reference: https://github.com/uber-go/zap/blob/master/buffer/buffer.go
Index ¶
- Variables
- type AtomicLevel
- type Buffer
- func (b *Buffer) AppendBool(v bool)
- func (b *Buffer) AppendByte(v byte)
- func (b *Buffer) AppendBytes(v []byte)
- func (b *Buffer) AppendFloat(f float64, bitSize int)
- func (b *Buffer) AppendInt(i int64)
- func (b *Buffer) AppendQuote(s string)
- func (b *Buffer) AppendString(s string)
- func (b *Buffer) AppendTime(t time.Time, layout string)
- func (b *Buffer) AppendUint(i uint64)
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Clone() *Buffer
- func (b *Buffer) Len() int
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) TrimNewline()
- func (b *Buffer) TryGrow(size int)
- func (b *Buffer) Write(bs []byte) (int, error)
- func (b *Buffer) WriteByte(v byte) error
- func (b *Buffer) WriteString(s string) (int, error)
- type CallerFormatter
- type CallerOption
- type ColorAttr
- type ConsoleEncoder
- type EncoderType
- type ErrorHandler
- type Field
- func Any(key string, value any) Field
- func Array(key string, value ...any) Field
- func ArrayT[T any](key string, value ...T) Field
- func Bool(key string, value bool) Field
- func Duration(key string, value time.Duration) Field
- func Error(key string, value error) Field
- func Float32(key string, value float32) Field
- func Float64(key string, value float64) Field
- func Int(key string, value int) Field
- func Int8(key string, value int8) Field
- func Int16(key string, value int16) Field
- func Int32(key string, value int32) Field
- func Int64(key string, value int64) Field
- func Object(key string, value ...Field) Field
- func String(key string, value string) Field
- func Time(key string, value time.Time) Field
- func UInt(key string, value uint) Field
- func UInt8(key string, value uint8) Field
- func UInt16(key string, value uint16) Field
- func UInt32(key string, value uint32) Field
- func UInt64(key string, value uint64) Field
- type FieldType
- type JsonEncoder
- type LevelOption
- type LevelType
- type LogContext
- func (lc *LogContext) AtomicLevel() *AtomicLevel
- func (lc *LogContext) Build() Logger
- func (lc *LogContext) Copy() *LogContext
- func (lc *LogContext) WithAtomicLevel(level *AtomicLevel) *LogContext
- func (lc *LogContext) WithCallerKey(enable bool, option CallerOption) *LogContext
- func (lc *LogContext) WithColorfulset(enable bool, attr TextColorAttri) *LogContext
- func (lc *LogContext) WithEncoder(encoder EncoderType) *LogContext
- func (lc *LogContext) WithErrorHandler(handler ErrorHandler) *LogContext
- func (lc *LogContext) WithEscapeQuote(enable bool) *LogContext
- func (lc *LogContext) WithFields(fields ...Field) *LogContext
- func (lc *LogContext) WithLevel(level LevelType) *LogContext
- func (lc *LogContext) WithLevelKey(enable bool, option LevelOption) *LogContext
- func (lc *LogContext) WithMsgKey(key string) *LogContext
- func (lc *LogContext) WithNewFields(fields ...Field) *LogContext
- func (lc *LogContext) WithReflectValue(enable bool) *LogContext
- func (lc *LogContext) WithTimeKey(enable bool, option TimeOption) *LogContext
- func (lc *LogContext) WithWriter(writer WriteSyncer) *LogContext
- type Logger
- type LoggerX
- func (l *LoggerX) Debug(msg string, fields ...Field)
- func (l *LoggerX) Debugf(format string, args ...any)
- func (l *LoggerX) Enabled(level LevelType) bool
- func (l *LoggerX) Error(msg string, fields ...Field)
- func (l *LoggerX) ErrorWith(err error)
- func (l *LoggerX) Errorf(format string, args ...any)
- func (l *LoggerX) Fatal(msg string, fields ...Field)
- func (l *LoggerX) FatalWith(err error)
- func (l *LoggerX) Fatalf(format string, args ...any)
- func (l *LoggerX) Info(msg string, fields ...Field)
- func (l *LoggerX) Infof(format string, args ...any)
- func (l *LoggerX) Panic(msg string, fields ...Field)
- func (l *LoggerX) PanicWith(err error)
- func (l *LoggerX) Panicf(format string, args ...any)
- func (l *LoggerX) Sync() error
- func (l *LoggerX) Trace(msg string, fields ...Field)
- func (l *LoggerX) Tracef(format string, args ...any)
- func (l *LoggerX) Warn(msg string, fields ...Field)
- func (l *LoggerX) Warnf(format string, args ...any)
- func (l *LoggerX) With(fields ...Field) Logger
- type TextColorAttri
- type TextEncoder
- type TimeOption
- type WriteSyncer
Constants ¶
This section is empty.
Variables ¶
var ( NoColor = os.Getenv("NO_COLOR") != "" || os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) Output = colorable.NewColorableStdout() )
var ConsoleEncoderSplitCharacter = byte('\t')
Functions ¶
This section is empty.
Types ¶
type AtomicLevel ¶
type AtomicLevel struct {
// contains filtered or unexported fields
}
func NewAtomicLevel ¶
func NewAtomicLevel(level LevelType) *AtomicLevel
func (*AtomicLevel) Level ¶
func (al *AtomicLevel) Level() LevelType
func (*AtomicLevel) SetLevel ¶
func (al *AtomicLevel) SetLevel(level LevelType)
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a thin wrapper around a byte slice. It's intended to be pooled, so the only way to construct one is via a Pool.
func (*Buffer) AppendBool ¶
AppendBool appends a bool to the underlying buffer.
func (*Buffer) AppendByte ¶
AppendByte writes a single byte to the Buffer.
func (*Buffer) AppendBytes ¶
AppendBytes writes the given slice of bytes to the Buffer.
func (*Buffer) AppendFloat ¶
AppendFloat appends a float to the underlying buffer. It doesn't quote NaN or +/- Inf.
func (*Buffer) AppendInt ¶
AppendInt appends an integer to the underlying buffer (assuming base 10).
func (*Buffer) AppendQuote ¶
func (*Buffer) AppendString ¶
AppendString writes a string to the Buffer.
func (*Buffer) AppendTime ¶
AppendTime appends the time formatted using the specified layout.
func (*Buffer) AppendUint ¶
AppendUint appends an unsigned integer to the underlying buffer (assuming base 10).
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the underlying byte slice. Subsequent writes re-use the slice's backing array.
func (*Buffer) TrimNewline ¶
func (b *Buffer) TrimNewline()
TrimNewline trims any final "\n" byte from the end of the buffer.
type CallerFormatter ¶
type CallerFormatter uint8
const ( // package/file:line ShortFile CallerFormatter = iota // /full/path/to/package/file:line FullFile // package/file:line package.func ShortFileFunc // /full/path/to/package/file:line package.func FullFileFunc )
type CallerOption ¶
type CallerOption struct {
// caller key, default: "caller"
CallerKey string
// file key of caller, default: "file"
FileKey string
// function key of caller, default: "func"
FuncKey string
// caller formatter, default: ShortFileCaller
Formatter CallerFormatter
// caller skips increases the number of callers skipped by caller annotation.
// when building wrappers around the Logger, supplying this Option prevents logx from always
// reporting the wrapper code as the caller. default: 0
CallerSkip int
}
type ConsoleEncoder ¶
type ConsoleEncoder struct {
*LogContext
// contains filtered or unexported fields
}
func (*ConsoleEncoder) Encode ¶
func (enc *ConsoleEncoder) Encode(ent entry, fields []Field) (ret *Buffer, err error)
func (*ConsoleEncoder) Init ¶
func (enc *ConsoleEncoder) Init()
type ErrorHandler ¶
type ErrorHandler func(error)
ErrorHandler receives errors produced while encoding, writing, or syncing a log entry. Implementations must be safe for concurrent use.
type JsonEncoder ¶
type JsonEncoder struct {
*LogContext
// contains filtered or unexported fields
}
func (*JsonEncoder) Encode ¶
func (enc *JsonEncoder) Encode(ent entry, fields []Field) (ret *Buffer, err error)
func (*JsonEncoder) Init ¶
func (enc *JsonEncoder) Init()
type LevelOption ¶
type LogContext ¶
type LogContext struct {
// contains filtered or unexported fields
}
func NewLogContext ¶
func NewLogContext() *LogContext
func (*LogContext) AtomicLevel ¶
func (lc *LogContext) AtomicLevel() *AtomicLevel
AtomicLevel returns the context's level. Because the caller can change the returned level, it becomes shared with loggers built afterwards, as if it had been passed to WithAtomicLevel.
func (*LogContext) Build ¶
func (lc *LogContext) Build() Logger
Build returns a logger with a snapshot of the current configuration, including the level. Only a shared AtomicLevel (see WithAtomicLevel and AtomicLevel) stays connected, for runtime updates.
func (*LogContext) Copy ¶
func (lc *LogContext) Copy() *LogContext
Copy snapshots the logger configuration with an independent dynamic level.
func (*LogContext) WithAtomicLevel ¶
func (lc *LogContext) WithAtomicLevel(level *AtomicLevel) *LogContext
WithAtomicLevel uses level as the minimum level. Loggers built from this context share it, so level.SetLevel changes their level at runtime. A nil level resets the context to its own, unshared level.
func (*LogContext) WithCallerKey ¶
func (lc *LogContext) WithCallerKey(enable bool, option CallerOption) *LogContext
func (*LogContext) WithColorfulset ¶
func (lc *LogContext) WithColorfulset(enable bool, attr TextColorAttri) *LogContext
func (*LogContext) WithEncoder ¶
func (lc *LogContext) WithEncoder(encoder EncoderType) *LogContext
func (*LogContext) WithErrorHandler ¶
func (lc *LogContext) WithErrorHandler(handler ErrorHandler) *LogContext
WithErrorHandler configures how internal encoding, write, and automatic high-severity sync errors are reported. Passing nil restores the default handler, which writes the error to standard error.
func (*LogContext) WithEscapeQuote ¶
func (lc *LogContext) WithEscapeQuote(enable bool) *LogContext
WithEscapeQuote controls escaping in Console output: strings in the embedded JSON fragment are JSON-escaped, and control characters in the message (such as newlines and tabs) are escaped so a message cannot forge extra log lines or columns. Console output is not escaped by default; prefer the Json or Text encoder for untrusted input. The Json encoder always performs standards-compliant escaping.
func (*LogContext) WithFields ¶
func (lc *LogContext) WithFields(fields ...Field) *LogContext
func (*LogContext) WithLevel ¶
func (lc *LogContext) WithLevel(level LevelType) *LogContext
WithLevel sets the minimum level. Loggers already built from this context keep their level, unless the level is a shared AtomicLevel (see WithAtomicLevel and AtomicLevel), in which case they observe the change.
func (*LogContext) WithLevelKey ¶
func (lc *LogContext) WithLevelKey(enable bool, option LevelOption) *LogContext
func (*LogContext) WithMsgKey ¶
func (lc *LogContext) WithMsgKey(key string) *LogContext
func (*LogContext) WithNewFields ¶
func (lc *LogContext) WithNewFields(fields ...Field) *LogContext
WithNewFields replaces inherited fields and copies the supplied slice.
func (*LogContext) WithReflectValue ¶
func (lc *LogContext) WithReflectValue(enable bool) *LogContext
func (*LogContext) WithTimeKey ¶
func (lc *LogContext) WithTimeKey(enable bool, option TimeOption) *LogContext
func (*LogContext) WithWriter ¶
func (lc *LogContext) WithWriter(writer WriteSyncer) *LogContext
type Logger ¶
type Logger interface {
Enabled(level LevelType) bool
Trace(msg string, fields ...Field)
Debug(msg string, fields ...Field)
Info(msg string, fields ...Field)
Warn(msg string, fields ...Field)
Error(msg string, fields ...Field)
Fatal(msg string, fields ...Field)
Panic(msg string, fields ...Field)
Tracef(format string, args ...any)
Debugf(format string, args ...any)
Infof(format string, args ...any)
Warnf(format string, args ...any)
Errorf(format string, args ...any)
Panicf(format string, args ...any)
Fatalf(format string, args ...any)
// PanicWith logs err's message at panic level, then panics with err.
// It does nothing when err is nil.
PanicWith(err error)
// ErrorWith logs err's message at error level. A nil err is logged as
// "<nil>".
ErrorWith(err error)
// FatalWith logs err's message at fatal level, then calls os.Exit(1).
// It does nothing, and does not exit, when err is nil.
FatalWith(err error)
With(fields ...Field) Logger
Sync() error
}
type LoggerX ¶
type LoggerX struct {
// contains filtered or unexported fields
}
type TextColorAttri ¶
type TextEncoder ¶
type TextEncoder struct {
*LogContext
// contains filtered or unexported fields
}
func (*TextEncoder) Encode ¶
func (enc *TextEncoder) Encode(ent entry, fields []Field) (ret *Buffer, err error)
func (*TextEncoder) Init ¶
func (enc *TextEncoder) Init()
type TimeOption ¶
type WriteSyncer ¶
func AddSync ¶
func AddSync(w io.Writer) WriteSyncer
func Lock ¶
func Lock(ws WriteSyncer) WriteSyncer
Lock wraps a WriteSyncer in a mutex to make it safe for concurrent use. In particular, *os.Files must be locked before use. See zap log