zapmw

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2020 License: MIT Imports: 7 Imported by: 0

README

PkgGoDev A basic net/http-compatible logging middleware based on go.uber.org/zap.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

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

Extract returns the *zap.Logger set by zapmw. If no logger is found in the context, zap.NewNop() is returned.

func New

func New(logger *zap.Logger, opts ...Option) func(next http.Handler) http.Handler

New returns a new logging middleware using the provided *zap.Logger

Types

type Option added in v0.2.0

type Option struct {
	// contains filtered or unexported fields
}

Option configures the logging middleware.

func WithClientErrorLevel added in v0.2.0

func WithClientErrorLevel(level zapcore.Level) Option

WithClientErrorLevel sets the log level for 4xx responses. The default is DebugLevel.

func WithRedirectionLevel added in v0.2.0

func WithRedirectionLevel(level zapcore.Level) Option

WithRedirectionLevel sets the log level for 3xx responses. The default is DebugLevel.

func WithReferrer added in v0.2.1

func WithReferrer() Option

WithReferrer adds a referrer field to the logger with the value of *http.Request.Referer().

func WithRemoteAddr added in v0.2.1

func WithRemoteAddr() Option

WithRemoteAddr adds a remote_addr field to the logger with the value of *http.Request.RemoteAddr.

func WithServerErrorLevel added in v0.2.0

func WithServerErrorLevel(level zapcore.Level) Option

WithServerErrorLevel sets the log level for 5xx responses. The default is ErrorLevel.

func WithSuccessLevel added in v0.2.0

func WithSuccessLevel(level zapcore.Level) Option

WithSuccessLevel sets the log level for 2xx responses. The default is DebugLevel.

func WithUserAgent added in v0.2.1

func WithUserAgent() Option

WithUserAgent adds a user_agent field to the logger with the value of *http.Request.UserAgent().

Jump to

Keyboard shortcuts

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