Back to godoc.org

Package log

v0.0.0-...-92f7cd3
Latest Go to latest

The highest tagged major version is .

Published: Jun 2, 2020 | License: MIT | Module: github.com/Kalinin-Andrey/otus-go/calendar

Index

func WithRequest

func WithRequest(ctx context.Context, req *http.Request) context.Context

WithRequest returns a context which knows the request ID and correlation ID in the given request.

type ILogger

type ILogger interface {
	// With returns a logger based off the root logger and decorates it with the given context and arguments.
	With(ctx context.Context, args ...interface{}) *Logger

	// Debug uses fmt.Sprint to construct and log a message at DEBUG level
	Debug(args ...interface{})
	// Info uses fmt.Sprint to construct and log a message at INFO level
	Info(args ...interface{})
	// Error uses fmt.Sprint to construct and log a message at ERROR level
	Error(args ...interface{})

	// Debugf uses fmt.Sprintf to construct and log a message at DEBUG level
	Debugf(format string, args ...interface{})
	// Infof uses fmt.Sprintf to construct and log a message at INFO level
	Infof(format string, args ...interface{})
	// Errorf uses fmt.Sprintf to construct and log a message at ERROR level
	Errorf(format string, args ...interface{})
	// Sync synchronises logging
	Sync() error
	// Print uses fmt.Sprint to construct and log a message at DEBUG level
	Print(v ...interface{})
}

ILogger interface

type Logger

type Logger struct {
	*zap.SugaredLogger
}

Logger struct

func New

func New(conf config.Log) (*Logger, error)

New creates a new logger

func NewByDefault

func NewByDefault() *Logger

NewByDefault creates a new logger using the default configuration.

func NewWithZap

func NewWithZap(l *zap.Logger) *Logger

NewWithZap creates a new logger using the preconfigured zap logger.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print for log interface

func (*Logger) With

func (l *Logger) With(ctx context.Context, args ...interface{}) *Logger

With returns a logger based off the root logger and decorates it with the given context and arguments.

If the context contains request ID and/or correlation ID information (recorded via WithRequestID() and WithCorrelationID()), they will be added to every log message generated by the new logger.

The arguments should be specified as a sequence of name, value pairs with names being strings. The arguments will also be added to every log message generated by the logger.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier