logutils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package logutils implements helpers for logging.

Index

Constants

This section is empty.

Variables

View Source
var Levels = []string{
	zap.DebugLevel.String(),
	zap.InfoLevel.String(),
	zap.WarnLevel.String(),
	zap.ErrorLevel.String(),
	zap.DPanicLevel.String(),
	zap.PanicLevel.String(),
	zap.FatalLevel.String(),
}

Functions

func ContextWithZap

func ContextWithZap(parent context.Context, logger *zap.Logger) context.Context

ContextWithZap returns a copy of parent context injected with corresponding zap logger.

func FlushZap

func FlushZap(logger *zap.Logger)

FlushZap triggers the Sync() on the logger. In case of an error, it will log it using the logger from standard library.

func GetZapLogger

func GetZapLogger(options ...LogConfigOption) (*zap.Logger, error)

GetZapLogger returns a logger created according to the provided options. In case if anything goes wrong (for example if the log-level string can not be parsed) it will return a logger (with configuration that is closest possible to the desired one) and an error.

func MustGetZapLogger

func MustGetZapLogger(options ...LogConfigOption) *zap.Logger

MustGetZapLogger is guaranteed to return a logger with configuration as close as possible to the desired one. Any errors encountered in the process will be logged as warnings with the resulting logger.

func RequestWithZap

func RequestWithZap(parent *http.Request, logger *zap.Logger) *http.Request

RequestWithZap returns a shallow copy of parent request with context being supplemented with corresponding zap logger.

func ZapFromContext

func ZapFromContext(ctx context.Context) *zap.Logger

ZapFromContext retrieves the zap logger passed with a context.

func ZapFromRequest

func ZapFromRequest(request *http.Request) *zap.Logger

ZapFromRequest retrieves the zap logger passed with request's context.

Types

type LogConfigOption

type LogConfigOption = func(*loggerConfig)

LogConfigOption allows to fine-tune the configuration of the logger.

func LogDevMode

func LogDevMode(devMode bool) LogConfigOption

LogDevMode tells the logger to work in the development mode.

func LogLevel

func LogLevel(level string) LogConfigOption

LogLevel sets the desired level of logging.

Jump to

Keyboard shortcuts

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