log

package
v0.0.0-...-92f7cd3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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.

Jump to

Keyboard shortcuts

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