Documentation ¶
Index ¶
- Constants
- Variables
- func Capped(cap int, v interface{}) string
- func Colored(s interface{}, colorNames ...string) string
- func ColoredWithCode(s interface{}, fg, bg Color) string
- func ColoredWithName(s interface{}, fgName, bgName string) string
- func DebugShowcase()
- func IsTerminal(w io.Writer) bool
- func Join(sep string, values ...interface{}) string
- func MakeKVFunc(ignored utils.StringSet) func(Fields) string
- func MakeLevelFunc(term bool) func(padding int, kvs Fields) string
- func MakeLevelPaddingFunc(v interface{}) func(int) string
- func MakeQuickColorFunc(fg Color) func(s interface{}) string
- func NewZapFormattedEncoder(cfg zapcore.EncoderConfig, formatter TextFormatter, isTerm bool) zapcore.Encoder
- func NewZapWriterWrapper(w io.Writer) zapcore.WriteSyncer
- func NoopColored(v interface{}, _ ...string) interface{}
- func NoopQuickColor(v interface{}) interface{}
- func Padding(padding int, v interface{}) string
- func Sprint(v interface{}) string
- func Trace(tid, sid, pid interface{}) string
- type Color
- type Fields
- type SliceArrayEncoder
- func (s *SliceArrayEncoder) AppendBool(v bool)
- func (s *SliceArrayEncoder) AppendByteString(v []byte)
- func (s *SliceArrayEncoder) AppendComplex128(v complex128)
- func (s *SliceArrayEncoder) AppendComplex64(v complex64)
- func (s *SliceArrayEncoder) AppendDuration(v time.Duration)
- func (s *SliceArrayEncoder) AppendFloat32(v float32)
- func (s *SliceArrayEncoder) AppendFloat64(v float64)
- func (s *SliceArrayEncoder) AppendInt(v int)
- func (s *SliceArrayEncoder) AppendInt16(v int16)
- func (s *SliceArrayEncoder) AppendInt32(v int32)
- func (s *SliceArrayEncoder) AppendInt64(v int64)
- func (s *SliceArrayEncoder) AppendInt8(v int8)
- func (s *SliceArrayEncoder) AppendString(v string)
- func (s *SliceArrayEncoder) AppendTime(v time.Time)
- func (s *SliceArrayEncoder) AppendUint(v uint)
- func (s *SliceArrayEncoder) AppendUint16(v uint16)
- func (s *SliceArrayEncoder) AppendUint32(v uint32)
- func (s *SliceArrayEncoder) AppendUint64(v uint64)
- func (s *SliceArrayEncoder) AppendUint8(v uint8)
- func (s *SliceArrayEncoder) AppendUintptr(v uintptr)
- func (s *SliceArrayEncoder) Latest() interface{}
- type TemplatedFormatter
- type TerminalAware
- type TextFormatter
- type ZapFormattedEncoder
- type ZapTerminalCore
- type ZapWriterWrapper
Constants ¶
const ( LogKeyMessage = "msg" LogKeyName = "logger" LogKeyTimestamp = "time" LogKeyCaller = "caller" LogKeyLevel = "level" LogKeyContext = "ctx" LogKeyStacktrace = "stacktrace" )
const ( Default = Color(iota) Black Red Green Yellow Blue Magenta Cyan Gray BoldBlack BoldRed BoldGreen BoldYellow BoldBlue BoldMagenta BoldCyan BoldGray )
Variables ¶
var ( TmplColorFuncMap template.FuncMap TmplColorFuncMapNonTerm template.FuncMap )
var ( FgColors []string BgColors []string ResetColor = "\x1b[39;49;22m" )
var ( TmplFuncMap = template.FuncMap{ "cap": Capped, "pad": Padding, "lvl": MakeLevelFunc(true), "join": Join, "trace": Trace, } TmplFuncMapNonTerm = template.FuncMap{ "cap": Capped, "pad": Padding, "lvl": MakeLevelFunc(false), "join": Join, "trace": Trace, } )
Note: https://pkg.go.dev/text/template#hdr-Pipelines chainable argument should be the last parameter of any function
var ColorNames = map[string]Color{ "black": Black, "red": Red, "green": Green, "yellow": Yellow, "blue": Blue, "magenta": Magenta, "cyan": Cyan, "gray": Gray, "black_b": BoldBlack, "red_b": BoldRed, "green_b": BoldGreen, "yellow_b": BoldYellow, "blue_b": BoldBlue, "magenta_b": BoldMagenta, "cyan_b": BoldCyan, "gray_b": BoldGray, }
ColorNames names can be used for generic color function. quick foreground color function with same name is also availalbe in template
Functions ¶
func Capped ¶
Capped truncate given value to specified length if cap > 0: with tailing "..." if truncated if cap < 0: with middle "..." if truncated
func Colored ¶
Colored takes 0, 1, or 2 color names when present, they should be in order of fgName, bgName
func ColoredWithCode ¶
func ColoredWithName ¶
func DebugShowcase ¶
func DebugShowcase()
func IsTerminal ¶
IsTerminal returns true if w writes to a terminal. Implementations adopted from github.com/go-kit/log/term
func MakeLevelPaddingFunc ¶
func MakeQuickColorFunc ¶
func NewZapFormattedEncoder ¶
func NewZapFormattedEncoder(cfg zapcore.EncoderConfig, formatter TextFormatter, isTerm bool) zapcore.Encoder
func NewZapWriterWrapper ¶
func NewZapWriterWrapper(w io.Writer) zapcore.WriteSyncer
NewZapWriterWrapper similar to zapcore.AddSync with exported type
func NoopColored ¶
func NoopColored(v interface{}, _ ...string) interface{}
func NoopQuickColor ¶
func NoopQuickColor(v interface{}) interface{}
func Trace ¶
func Trace(tid, sid, pid interface{}) string
Trace generate shortest possible tracing info string:
- if trace ID is not available, return empty string
- if span ID is same as trace ID, we assume parent ID is 0 and only returns traceID
- if span ID is different from trace ID and parent ID is same as trace ID, we only returns trace ID and span ID
Types ¶
type SliceArrayEncoder ¶
type SliceArrayEncoder struct {
// contains filtered or unexported fields
}
SliceArrayEncoder implementing zapcore.PrimitiveArrayEncoder. It's used to apply zapcore's entry encoders like zapcore.NameEncoder
func (*SliceArrayEncoder) AppendBool ¶
func (s *SliceArrayEncoder) AppendBool(v bool)
func (*SliceArrayEncoder) AppendByteString ¶
func (s *SliceArrayEncoder) AppendByteString(v []byte)
func (*SliceArrayEncoder) AppendComplex128 ¶
func (s *SliceArrayEncoder) AppendComplex128(v complex128)
func (*SliceArrayEncoder) AppendComplex64 ¶
func (s *SliceArrayEncoder) AppendComplex64(v complex64)
func (*SliceArrayEncoder) AppendDuration ¶
func (s *SliceArrayEncoder) AppendDuration(v time.Duration)
func (*SliceArrayEncoder) AppendFloat32 ¶
func (s *SliceArrayEncoder) AppendFloat32(v float32)
func (*SliceArrayEncoder) AppendFloat64 ¶
func (s *SliceArrayEncoder) AppendFloat64(v float64)
func (*SliceArrayEncoder) AppendInt ¶
func (s *SliceArrayEncoder) AppendInt(v int)
func (*SliceArrayEncoder) AppendInt16 ¶
func (s *SliceArrayEncoder) AppendInt16(v int16)
func (*SliceArrayEncoder) AppendInt32 ¶
func (s *SliceArrayEncoder) AppendInt32(v int32)
func (*SliceArrayEncoder) AppendInt64 ¶
func (s *SliceArrayEncoder) AppendInt64(v int64)
func (*SliceArrayEncoder) AppendInt8 ¶
func (s *SliceArrayEncoder) AppendInt8(v int8)
func (*SliceArrayEncoder) AppendString ¶
func (s *SliceArrayEncoder) AppendString(v string)
func (*SliceArrayEncoder) AppendTime ¶
func (s *SliceArrayEncoder) AppendTime(v time.Time)
func (*SliceArrayEncoder) AppendUint ¶
func (s *SliceArrayEncoder) AppendUint(v uint)
func (*SliceArrayEncoder) AppendUint16 ¶
func (s *SliceArrayEncoder) AppendUint16(v uint16)
func (*SliceArrayEncoder) AppendUint32 ¶
func (s *SliceArrayEncoder) AppendUint32(v uint32)
func (*SliceArrayEncoder) AppendUint64 ¶
func (s *SliceArrayEncoder) AppendUint64(v uint64)
func (*SliceArrayEncoder) AppendUint8 ¶
func (s *SliceArrayEncoder) AppendUint8(v uint8)
func (*SliceArrayEncoder) AppendUintptr ¶
func (s *SliceArrayEncoder) AppendUintptr(v uintptr)
func (*SliceArrayEncoder) Latest ¶
func (s *SliceArrayEncoder) Latest() interface{}
type TemplatedFormatter ¶
type TemplatedFormatter struct {
// contains filtered or unexported fields
}
func NewTemplatedFormatter ¶
func NewTemplatedFormatter(tmpl string, fixedFields utils.StringSet, isTerm bool) *TemplatedFormatter
type TerminalAware ¶
type TerminalAware interface {
IsTerminal() bool
}
type ZapFormattedEncoder ¶
type ZapFormattedEncoder struct { *zapcore.MapObjectEncoder Formatter TextFormatter Config *zapcore.EncoderConfig IsTerminal bool }
ZapFormattedEncoder implements zapcore.Encoder. This encoder leverage go template system for render user defined log. Note: Unlike zapcore's JSONEncoder and ConsoleEncoder, this encoder focus on flexibility rather than performance.
When performance is crucial, JSON format of log should be used.
func (*ZapFormattedEncoder) Clone ¶
func (enc *ZapFormattedEncoder) Clone() zapcore.Encoder
func (*ZapFormattedEncoder) EncodeEntry ¶
func (enc *ZapFormattedEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
EncodeEntry implements zapcore.Encoder We use map and slice based encoders. Working with map and slice is necessary with go template based formatter. Map and slice operations is not the most performant approach, but it wouldn't be the bottleneck comparing to go template rendering
type ZapTerminalCore ¶
ZapTerminalCore implements TerminalAware and always returns true
func (ZapTerminalCore) IsTerminal ¶
func (s ZapTerminalCore) IsTerminal() bool
type ZapWriterWrapper ¶
ZapWriterWrapper implements zapcore.WriteSyncer and TerminalAware
func (ZapWriterWrapper) IsTerminal ¶
func (s ZapWriterWrapper) IsTerminal() bool
func (ZapWriterWrapper) Sync ¶
func (ZapWriterWrapper) Sync() error