zapx: go.bobheadxi.dev/zapx/zapx Index | Files

package zapx

import "go.bobheadxi.dev/zapx/zapx"

Package zapx provides simple extensions to the base zap logger.

TODO: examples

Index

Package Files

doc.go fields.go format.go io.go option.go wrappers.go zapx.go

func FieldSet Uses

func FieldSet(key string, fields ...zap.Field) zap.Field

FieldSet allows logging of sets of fields as a log object TODO: not as performant as testdata.Obj for some reason, need to look into why

func New Uses

func New(logpath string, dev bool, opts ...Option) (l *zap.Logger, err error)

New creates a default zap logger based with basic defaults. If `logpath` is set, will use json encoder and write to the provided filepath. If `dev` is true, will use zap.DevelopmentConfig with colors enabled, though if logpath is set, the json encoder (without colors) will be enforced. If `dev` is false, will use zap.ProductionConfig.

func NewToWriter Uses

func NewToWriter(
    w io.Writer,
    level zapcore.Level,
    enc zapcore.Encoder,
) *zap.Logger

NewToWriter instantiates a simple zap logger that writes to the given writer

func WrapWithLevel Uses

func WrapWithLevel(level zapcore.Level) zap.Option

WrapWithLevel is a zap.Option that spawns a child logger at the specified level

type FieldSetMarshaller Uses

type FieldSetMarshaller interface {
    zapcore.ObjectMarshaler
    Fields() []zap.Field
}

FieldSetMarshaller is the underlying type used by zapx.Fields()

type FormatLogger Uses

type FormatLogger interface {
    Errorf(string, ...interface{})
    Warningf(string, ...interface{})
    Infof(string, ...interface{})
    Debugf(string, ...interface{})
}

FormatLogger exposes a common format-based logger interface

type Option Uses

type Option func(*zap.Config) error

Option denotes an option for the zapx constructor

func OnlyToFile Uses

func OnlyToFile() Option

OnlyToFile removes all other outputs and only writes to file

func WithDebug Uses

func WithDebug(debug bool) Option

WithDebug sets log level to debug if given bool is true

func WithFields Uses

func WithFields(fields map[string]interface{}) Option

WithFields sets initial fields in the configuration

type ZapFormatLogger Uses

type ZapFormatLogger struct {
    L *zap.Logger
}

ZapFormatLogger implements FormatLogger using the given zap logger

func NewFormatLogger Uses

func NewFormatLogger(l *zap.Logger) *ZapFormatLogger

NewFormatLogger instantiates a new default ZapFormatLogger

func (*ZapFormatLogger) Debugf Uses

func (z *ZapFormatLogger) Debugf(f string, v ...interface{})

Debugf logs at the debug level

func (*ZapFormatLogger) Errorf Uses

func (z *ZapFormatLogger) Errorf(f string, v ...interface{})

Errorf logs at the error level

func (*ZapFormatLogger) Infof Uses

func (z *ZapFormatLogger) Infof(f string, v ...interface{})

Infof logs at the info level

func (*ZapFormatLogger) Warningf Uses

func (z *ZapFormatLogger) Warningf(f string, v ...interface{})

Warningf logs at the warn level

Package zapx imports 7 packages (graph) and is imported by 5 packages. Updated 2019-10-07. Refresh now. Tools for package owners.