Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrFailedToInitLogger = errors.New("failed to initialize logger")
)
Predefined errors.
Functions ¶
func DefaultSkipper ¶
DefaultSkipper is a function that always returns false. It can be used as a default value for the skipper argument of LogRequestWithSkipper.
func LogRequest ¶
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 ¶
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.