loggerext

package module
v0.4.1 Latest Latest
Warning

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

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

README

Go ApiServer Middleware Logger Ext License

Provide an extension of github.com/xgfone/go-apiserver/http/middleware/logger to support to log the request and response header and body, requiring Go1.21+ and github.com/xgfone/[email protected]+.

Usage
import _ "github.com/xgfone/go-apiserver-middleware-logger-ext"

Documentation

Overview

Package loggerext provides an extension of "github.com/xgfone/go-apiserver/http/middleware/logger" to support to log the request and response header and body.

Usage

import (
	loggerext "github.com/xgfone/go-apiserver-middleware-logger-ext"
	"github.com/xgfone/go-apiserver/http/router"
)

router.DefaultRouter.Middlewares.InsertFunc(loggerext.WrapHandler)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect added in v0.2.0

func Collect(w http.ResponseWriter, r *http.Request, appendAttr func(...slog.Attr))

Collect collects the key-value log information and appends them by appendAttr.

func DisableLogRespBody added in v0.3.0

func DisableLogRespBody(ctx context.Context) context.Context

DisableLogRespBody returns a new context to set a flag to indicate not to log the response body.

If not set, use the default policy.

func Enabled added in v0.2.0

func Enabled(req *http.Request) bool

Enabled reports whether to log the request.

func Release added in v0.2.0

func Release(w http.ResponseWriter, r *http.Request)

Release tries to release the buffer into the pool.

func WrapHandler added in v0.2.0

func WrapHandler(next http.Handler) http.Handler

WrapHandler wraps a http handler and returns a new, which will replace the request and response writer, so must be used before the logger middleware.

func WrapReqRespBody added in v0.2.0

func WrapReqRespBody(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)

WrapReqRespBody wraps the http request and response writer, and returns the new, which is used by the http middleware, such as WrapHandler.

NOTICE: Release should be called after handling the request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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