log

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ZapContextWithFields added in v0.2.1

func ZapContextWithFields(ctx context.Context, fields ...zap.Field) context.Context

ZapContextWithFields will add Zap Fields to logger in Context

Types

type Logger

type Logger interface {

	// Debug level message with alternating key/value pairs
	// key should be string, value could be anything printable
	Debug(msg string, args ...interface{})

	// Info level message with alternating key/value pairs
	// key should be string, value could be anything printable
	Info(msg string, args ...interface{})

	// Warn level message with alternating key/value pairs
	// key should be string, value could be anything printable
	Warn(msg string, args ...interface{})

	// Error level message with alternating key/value pairs
	// key should be string, value could be anything printable
	Error(msg string, args ...interface{})

	// Fatal level message with alternating key/value pairs
	// key should be string, value could be anything printable
	Fatal(msg string, args ...interface{})

	// Level returns priority level for which this logger will filter logs
	Level() string

	// Writer used to print logs
	Writer() io.Writer
}

Logger is a convenient interface to use provided loggers either use it as it is or implement your own interface where the logging implementations are used Each log method must take first string as message and then one or more key,value arguments. For example:

timeTaken := time.Duration(time.Second * 1)
l.Debug("processed request", "time taken", timeTaken)

here key should always be a `string` and value could be of any type as long as it is printable.

l.Info("processed request", "time taken", timeTaken, "started at", startedAt)

type Logrus

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

func NewLogrus

func NewLogrus(opts ...Option) *Logrus

NewLogrus returns a logrus logger instance with info level as default log level

func (*Logrus) Debug

func (l *Logrus) Debug(msg string, args ...interface{})

func (*Logrus) Entry

func (l *Logrus) Entry(args ...interface{}) *logrus.Entry

func (*Logrus) Error

func (l *Logrus) Error(msg string, args ...interface{})

func (*Logrus) Fatal

func (l *Logrus) Fatal(msg string, args ...interface{})

func (*Logrus) Info

func (l *Logrus) Info(msg string, args ...interface{})

func (*Logrus) Level

func (l *Logrus) Level() string

func (*Logrus) Warn

func (l *Logrus) Warn(msg string, args ...interface{})

func (*Logrus) Writer

func (l *Logrus) Writer() io.Writer

type Noop

type Noop struct{}

func NewNoop

func NewNoop(opts ...Option) *Noop

NewNoop returns a no operation logger, useful in tests

func (*Noop) Debug

func (n *Noop) Debug(msg string, args ...interface{})

func (*Noop) Error

func (n *Noop) Error(msg string, args ...interface{})

func (*Noop) Fatal

func (n *Noop) Fatal(msg string, args ...interface{})

func (*Noop) Info

func (n *Noop) Info(msg string, args ...interface{})

func (*Noop) Level

func (n *Noop) Level() string

func (*Noop) Warn

func (n *Noop) Warn(msg string, args ...interface{})

func (*Noop) Writer

func (n *Noop) Writer() io.Writer

type Option

type Option func(interface{})

Option modifies the logger behavior

func LogrusWithFormatter

func LogrusWithFormatter(f logrus.Formatter) Option

LogrusWithFormatter can be used to change default formatting by implementing logrus.Formatter For example:

type PlainFormatter struct{}
func (p *PlainFormatter) Format(entry *logrus.Entry) ([]byte, error) {
    return []byte(entry.Message), nil
}
l := log.NewLogrus(log.LogrusWithFormatter(&PlainFormatter{}))

func LogrusWithLevel

func LogrusWithLevel(level string) Option

func LogrusWithWriter

func LogrusWithWriter(writer io.Writer) Option

func ZapWithConfig

func ZapWithConfig(conf zap.Config, opts ...zap.Option) Option

func ZapWithNoop

func ZapWithNoop() Option

type Zap

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

func NewZap

func NewZap(opts ...Option) *Zap

NewZap returns a zap logger instance with info level as default log level

func ZapFromContext added in v0.2.1

func ZapFromContext(ctx context.Context) Zap

ZapFromContext will help in fetching back zap logger from context

func (Zap) Debug

func (z Zap) Debug(msg string, args ...interface{})

func (Zap) Error

func (z Zap) Error(msg string, args ...interface{})

func (Zap) Fatal

func (z Zap) Fatal(msg string, args ...interface{})

func (Zap) GetInternalZapLogger

func (z Zap) GetInternalZapLogger() *zap.SugaredLogger

GetInternalZapLogger Gets internal SugaredLogger instance

func (Zap) Info

func (z Zap) Info(msg string, args ...interface{})

func (Zap) Level

func (z Zap) Level() string

func (Zap) NewContext

func (z Zap) NewContext(ctx context.Context) context.Context

NewContext will add Zap inside context

func (Zap) Warn

func (z Zap) Warn(msg string, args ...interface{})

func (Zap) Writer

func (z Zap) Writer() io.Writer

Jump to

Keyboard shortcuts

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