encoder

package
v0.0.0-...-dcf77fd Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bright = ansi.ColorCode("default+b")

Bright is the color used for the message

View Source
var DefaultColors = Colors{
	Debug: ansi.ColorCode("cyan"),
	Info:  ansi.ColorCode("green+h"),
	Warn:  ansi.ColorCode("yellow+bh"),
	Error: ansi.ColorCode("red+bh"),
}

DefaultColors is the default instance of Colors, used as the default colors if a nil Colorizer is passed to NewColorizedConsoleEncoder.

View Source
var Dim = ansi.ColorCode("240")

Dim is the color used for context keys, time, and caller information

Functions

func AbbrLevelEncoder

func AbbrLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

AbbrLevelEncoder encodes logging levels to the strings in the log entries. Encodes levels as 3-char abbreviations in upper case.

encConfig := flume.EncoderConfig{}
encConfig.EncodeTime = flume.AbbrLevelEncoder

func JustTimeEncoder

func JustTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

JustTimeEncoder is a timestamp encoder function which encodes time as a simple time of day, without a date. Intended for development and testing. Not good in a production system, where you probably need to know the date.

encConfig := flume.EncoderConfig{}
encConfig.EncodeTime = flume.JustTimeEncoder

func NewColorizedConsoleEncoder

func NewColorizedConsoleEncoder(cfg *zapcore.EncoderConfig, colorizer Colorizer) zapcore.Encoder

NewColorizedConsoleEncoder creates a console encoder, like NewConsoleEncoder, but colors the text with ansi escape codes. `colorize` configures which colors to use for each level.

If `colorizer` is nil, it will default to DefaultColors.

`github.com/mgutz/ansi` is a convenient package for getting color codes, e.g.:

ansi.ColorCode("red")

func NewConsoleEncoder

func NewConsoleEncoder(cfg *zapcore.EncoderConfig) zapcore.Encoder

NewConsoleEncoder creates an encoder whose output is designed for human - rather than machine - consumption. It serializes the core log entry data (message, level, timestamp, etc.) in a plain-text format. The context is encoded in LTSV.

Note that although the console encoder doesn't use the keys specified in the encoder configuration, it will omit any element whose key is set to the empty string.

func NewDevelopmentEncoderConfig

func NewDevelopmentEncoderConfig() zapcore.EncoderConfig

NewDevelopmentEncoderConfig returns an EncoderConfig which is intended for local development.

func NewEncoderConfig

func NewEncoderConfig() zapcore.EncoderConfig

NewEncoderConfig returns an EncoderConfig with default settings.

func NewLTSVEncoder

func NewLTSVEncoder(cfg *zapcore.EncoderConfig) zapcore.Encoder

NewLTSVEncoder creates a fast, low-allocation LTSV encoder.

Types

type Colorizer

type Colorizer interface {
	Level(l zapcore.Level) string
}

Colorizer returns ansi escape sequences for the colors for each log level. See Colors for a default implementation.

type Colors

type Colors struct {
	Debug, Info, Warn, Error string
}

Colors is an implementation of the Colorizer interface, which assigns colors to the default log levels.

func (*Colors) Level

func (c *Colors) Level(l zapcore.Level) string

Level implements Colorizer

Jump to

Keyboard shortcuts

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