logger

package
v0.0.0-...-a974e34 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToInitLogger = errors.New("failed to initialize logger")
)

Predefined errors.

Functions

func DefaultSkipper

func DefaultSkipper(r *http.Request) bool

DefaultSkipper is a function that always returns false. It can be used as a default value for the skipper argument of LogRequestWithSkipper.

func LogRequest

func LogRequest(log *zap.SugaredLogger) func(http.Handler) http.Handler

LogRequest is a middleware function that logs incoming HTTP requests. It takes a *zap.SugaredLogger as input and returns a function that can be used as middleware. The returned function wraps the provided http.Handler and logs information about the request. It logs the HTTP method, remote address, request path, and duration of the request.

func LogRequestWithSkipper

func LogRequestWithSkipper(log *zap.SugaredLogger, skipper func(r *http.Request) bool) func(http.Handler) http.Handler

LogRequestWithSkipper is a middleware function that logs incoming HTTP requests. It takes a *zap.SugaredLogger and a Skipper function as input and returns a function that can be used as middleware. The returned function wraps the provided http.Handler and logs information about the request. It logs the HTTP method, remote address, request path, and duration of the request. The Skipper function is used to determine if the request should be logged.

func New

func New(cnf Config) (*zap.Logger, error)

New creates a new logger instance based on the provided configuration. It returns a pointer to a zap.Logger and an error if the logger initialization fails. The logger is configured based on the provided Config struct, which includes options such as the application environment, debug mode, log level, additional fields, and whether to replace the global logger.

Types

type Config

type Config struct {
	AppEnv    string
	Level     string
	DebugMode bool
	Global    bool
	Fields    map[string]interface{}
}

Config defines the configuration for the logger.

Jump to

Keyboard shortcuts

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