logecho

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 5 Imported by: 3

README

LogZ for echo middleware

Helpful middleware for echo framework.

go get github.com/worldline-go/logz/logecho

Usage

e.Use(
    middleware.RequestID(),
    middleware.RequestLoggerWithConfig(logecho.RequestLoggerConfig()),
    logecho.ZerologLogger(),
)

To get back the logger from the context:

// this will show the request ID in the log
log.Ctx(c.Request().Context()).Info().Msg("Hello world")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestLoggerConfig

func RequestLoggerConfig(opts ...Option) middleware.RequestLoggerConfig

RequestLoggerConfig returns a middleware.RequestLoggerConfig with the given options.

func ZerologLogger

func ZerologLogger(opts ...Option) echo.MiddlewareFunc

ZerologLogger returns a middleware that adds a zerolog logger to the context with request_id.

For request_id, it uses the echo.HeaderXRequestID header (X-Request-Id). WithLevel not meaningful here, as the level is set in the log message.

Use after middleware.RequestID().

Types

type Option

type Option func(options *options)

func WithLevel

func WithLevel(level zerolog.Level) Option

WithLevel sets the log level for the logger, default is debug.

func WithLogger

func WithLogger(logger zerolog.Logger) Option

WithLogger sets the logger to use, default is log.Logger.

Jump to

Keyboard shortcuts

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