func ResetColor() string
func SetSequence(s uint64)
SetSequence explicitly sets the global sequence number.
type Color uint8
const ( ColorBlack Color = iota + 30 ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite )
const ColorNone Color = 0
func (c Color) Bold() string
func (c Color) Normal() string
A ColorFormatter formats an SGR color code.
type ColorFormatter struct { Bold bool // set the bold attribute Reset bool // reset colors and attributes }
func (c ColorFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the SGR color code to the provided writer.
func (c ColorFormatter) LevelColor(l zapcore.Level) Color
LevelColor returns the Color associated with a specific zap logging level.
A FormatEncoder is a zapcore.Encoder that formats log records according to a go-logging based format specifier.
type FormatEncoder struct { zapcore.Encoder // contains filtered or unexported fields }
func NewFormatEncoder(formatters ...Formatter) *FormatEncoder
func (f *FormatEncoder) Clone() zapcore.Encoder
Clone creates a new instance of this encoder with the same configuration.
func (f *FormatEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
EncodeEntry formats a zap log record. The structured fields are formatted by a zapcore.ConsoleEncoder and are appended as JSON to the end of the formatted entry. All entries are terminated by a newline.
A Formatter is used to format and write data from a zap log entry.
type Formatter interface { Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field) }
func NewFormatter(verb, format string) (Formatter, error)
NewFormatter creates the formatter for the provided verb. When a format is not provided, the default format for the verb is used.
func ParseFormat(spec string) ([]Formatter, error)
ParseFormat parses a log format spec and returns a slice of formatters that should be iterated over to build a formatted log record.
The op-loggng specifiers supported by this formatter are:
- %{color} - level specific SGR color escape or SGR reset - %{id} - a unique log sequence number - %{level} - the log level of the entry - %{message} - the log message - %{module} - the zap logger name - %{shortfunc} - the name of the function creating the log record - %{time} - the time the log entry was created
Specifiers may include an optional format verb:
- color: reset|bold - id: a fmt style numeric formatter without the leading % - level: a fmt style string formatter without the leading % - message: a fmt style string formatter without the leading % - module: a fmt style string formatter without the leading %
LevelFormatter formats a log level.
type LevelFormatter struct{ FormatVerb string }
func (l LevelFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the logging level to the provided writer.
MessageFormatter formats a log message.
type MessageFormatter struct{ FormatVerb string }
func (m MessageFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the log entry message to the provided writer.
ModuleFormatter formats the zap logger name.
type ModuleFormatter struct{ FormatVerb string }
func (m ModuleFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the zap logger name to the specified writer.
A MultiFormatter presents multiple formatters as a single Formatter. It can be used to change the set of formatters associated with an encoder at runtime.
type MultiFormatter struct {
// contains filtered or unexported fields
}
func NewMultiFormatter(formatters ...Formatter) *MultiFormatter
NewMultiFormatter creates a new MultiFormatter that delegates to the provided formatters. The formatters are used in the order they are presented.
func (m *MultiFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format iterates over its delegates to format a log record to the provided buffer.
func (m *MultiFormatter) SetFormatters(formatters []Formatter)
SetFormatters replaces the delegate formatters.
SequenceFormatter formats a global sequence number.
type SequenceFormatter struct{ FormatVerb string }
func (s SequenceFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
SequenceFormatter increments a global sequence number and writes it to the provided writer.
ShortFuncFormatter formats the name of the function creating the log record.
type ShortFuncFormatter struct{ FormatVerb string }
func (s ShortFuncFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the calling function name to the provided writer. The name is obtained from the runtime and the package and line numbers are discarded.
A StringFormatter formats a fixed string.
type StringFormatter struct{ Value string }
func (s StringFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the formatter's fixed string to provided writer.
TimeFormatter formats the time from the zap log entry.
type TimeFormatter struct{ Layout string }
func (t TimeFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field)
Format writes the log record time stamp to the provided writer.