zaptextenc

package module
v0.0.0-...-0272a73 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2016 License: MIT Imports: 8 Imported by: 0

README

⚡ zaptextenc

Text encoder for blazing fast, structured, leveled logging in Go.

Installation

go get -u github.com/akabos/zaptextenc

Usage

import (
    github.com/akabos/zaptextenc
    github.com/uber-go/zap
)

logger := zap.New(zaptextenc.New())

logger.Info("Failed to fetch URL.",
  zap.String("url", url),
  zap.Int("attempt", tryNum),
  zap.Duration("backoff", sleepFor),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) zap.Encoder

New ...

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a byte buffer

func NewBuffer

func NewBuffer(size uint) *Buffer

NewBuffer is Buffer constructor

func (*Buffer) Append

func (b *Buffer) Append(a ...byte)

Append ...

func (*Buffer) AppendString

func (b *Buffer) AppendString(a string)

AppendString ...

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes ...

func (*Buffer) Len

func (b *Buffer) Len() int

Len ...

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset clears buffer contents without re-allocation

func (*Buffer) Set

func (b *Buffer) Set(a []byte)

Set ...

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is zap.Encoder implementation that writes plain text messages

func (*Encoder) AddBool

func (enc *Encoder) AddBool(key string, value bool)

AddBool ...

func (*Encoder) AddFloat64

func (enc *Encoder) AddFloat64(key string, value float64)

AddFloat64 ...

func (*Encoder) AddInt

func (enc *Encoder) AddInt(key string, value int)

AddInt ...

func (*Encoder) AddInt64

func (enc *Encoder) AddInt64(key string, value int64)

AddInt64 ...

func (*Encoder) AddMarshaler

func (enc *Encoder) AddMarshaler(key string, marshaler zap.LogMarshaler) error

AddMarshaler ...

func (*Encoder) AddObject

func (enc *Encoder) AddObject(key string, value interface{}) error

AddObject ...

func (*Encoder) AddString

func (enc *Encoder) AddString(key, value string)

AddString ...

func (*Encoder) AddUint

func (enc *Encoder) AddUint(key string, value uint)

AddUint ...

func (*Encoder) AddUint64

func (enc *Encoder) AddUint64(key string, value uint64)

AddUint64 ...

func (*Encoder) Clone

func (enc *Encoder) Clone() zap.Encoder

Clone ...

func (*Encoder) Free

func (enc *Encoder) Free()

Free ...

func (*Encoder) WriteEntry

func (enc *Encoder) WriteEntry(w io.Writer, message string, level zap.Level, time time.Time) error

WriteEntry ...

type FixedWidthMessageFormatterOption

type FixedWidthMessageFormatterOption struct {
	// contains filtered or unexported fields
}

FixedWidthMessageFormatterOption is an option for fixed width log message format

func (FixedWidthMessageFormatterOption) Apply

Apply option to encoder

type LayoutTimeFormatterOption

type LayoutTimeFormatterOption struct {
	// contains filtered or unexported fields
}

LayoutTimeFormatterOption is an option for log entry time formatting according to specified layout

func (LayoutTimeFormatterOption) Apply

func (f LayoutTimeFormatterOption) Apply(e *Encoder)

Apply option to encoder

type LevelFormatter

type LevelFormatter func(*Buffer, zap.Level)

LevelFormatter is a func used to render log entry level

type LevelMap

type LevelMap map[zap.Level][]byte

LevelMap defines a mapping between log level and it's representation

type LevelMapFormatterOption

type LevelMapFormatterOption struct {
	// contains filtered or unexported fields
}

LevelMapFormatterOption is an option for level formatting according to a mapping

func (LevelMapFormatterOption) Apply

func (f LevelMapFormatterOption) Apply(e *Encoder)

Apply sets level formatter for an encoder

type MessageFormatter

type MessageFormatter func(*Buffer, string)

MessageFormatter is a func used to render log entry message

type NoLevelFormatterOption

type NoLevelFormatterOption struct{}

NoLevelFormatterOption defines an option which makes encoder to skip log level

func (NoLevelFormatterOption) Apply

func (f NoLevelFormatterOption) Apply(e *Encoder)

Apply sets level formatter for an encoder

type NoTimeFormatterOption

type NoTimeFormatterOption struct{}

NoTimeFormatterOption defines an option which makes encoder to skip log level

func (NoTimeFormatterOption) Apply

func (f NoTimeFormatterOption) Apply(e *Encoder)

Apply sets level formatter for an encoder

type Option

type Option interface {
	Apply(*Encoder)
}

Option is an Encoder option

func AbbrLevel

func AbbrLevel() Option

AbbrLevel formats log level as 3-letter abbreviation

func FixedWidthMessage

func FixedWidthMessage(width int) Option

FixedWidthMessage returns option for trimming/expanding log message to specified width

func NoLevel

func NoLevel() Option

NoLevel skips log level

func NoTime

func NoTime() Option

NoTime skips log entry time

func RFC3339Time

func RFC3339Time() Option

RFC3339Time format

func ShortTime

func ShortTime() Option

ShortTime format

func SimpleColorLevel

func SimpleColorLevel() Option

SimpleColorLevel formats log level as colored level names

func SimpleLevel

func SimpleLevel() Option

SimpleLevel formats log level in most dull and unfancy way possible

func SimpleMessage

func SimpleMessage() Option

SimpleMessage formats log message in most dull and unfancy way possible

func UnixNanoTime

func UnixNanoTime() Option

UnixNanoTime ...

func UnixTime

func UnixTime() Option

UnixTime ...

type SimpleMessageFormatterOption

type SimpleMessageFormatterOption struct{}

SimpleMessageFormatterOption is an option for simple log message format

func (SimpleMessageFormatterOption) Apply

Apply option to encoder

type TimeFormatter

type TimeFormatter func(*Buffer, time.Time)

TimeFormatter is a func used to render log entry time

type UnixNanoTimeFormatterOption

type UnixNanoTimeFormatterOption struct{}

UnixNanoTimeFormatterOption is an option for formatting entry time as nanoseconds since epoch

func (UnixNanoTimeFormatterOption) Apply

Apply option to encoder

type UnixTimeFormatterOption

type UnixTimeFormatterOption struct{}

UnixTimeFormatterOption is an option for formatting entry time as seconds since epoch

func (UnixTimeFormatterOption) Apply

func (f UnixTimeFormatterOption) Apply(e *Encoder)

Apply option to encoder

Jump to

Keyboard shortcuts

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