log

package module
v0.0.0-...-ded953e Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 6 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package log provides context-aware and structured logging capabilities.

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 Logger

type Logger 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{})
}

Logger is a logger that supports log levels, context and structured logging.

func New

func New() Logger

New creates a new logger using the default configuration.

func NewForTest

func NewForTest() (Logger, *observer.ObservedLogs)

NewForTest returns a new logger and the corresponding observed logs which can be used in unit tests to verify log entries.

func NewWithZap

func NewWithZap(l *zap.Logger) Logger

NewWithZap creates a new logger using the preconfigured zap logger.

Jump to

Keyboard shortcuts

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