req2log

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TypeValue = "request.2"
)

Variables

This section is empty.

Functions

func SetRequestParamPerms

func SetRequestParamPerms(perms RequestParamPerms)

func ToParams added in v1.13.0

func ToParams(r Request, idsExtractor extractor.IDsFromRequest, pathParamPerms, queryParamPerms, headerParamPerms ParamPerms) []wlog.Param

func WithLogger added in v1.32.0

func WithLogger(ctx context.Context, logger Logger) context.Context

WithLogger returns a copy of the provided context with the provided Logger included as a value. This operation will replace any logger that was previously set on the context.

Types

type Logger

type Logger interface {
	Request(req Request)

	RequestParamPerms
}

Logger creates a request log entry based on the provided information.

func FromContext added in v1.32.0

func FromContext(ctx context.Context) Logger

FromContext returns the Logger stored in the provided context. If no logger is set on the context, returns the logger created by calling DefaultLogger.

func New

func New(w io.Writer, params ...LoggerCreatorParam) Logger

func NewFromCreator

func NewFromCreator(w io.Writer, creator wlog.LoggerCreator, params ...LoggerCreatorParam) Logger

type LoggerBuilder added in v1.13.0

type LoggerBuilder interface {
	LoggerCreator(creator wlog.LoggerCreator)
	IdsExtractor(idsExtractor extractor.IDsFromRequest)

	SafePathParams(safePathParams []string)
	ForbiddenPathParams(forbiddenPathParams []string)

	SafeQueryParams(safeQueryParams []string)
	ForbiddenQueryParams(forbiddenQueryParams []string)

	SafeHeaderParams(safeHeaderParams []string)
	ForbiddenHeaderParams(forbiddenHeaderParams []string)
}

type LoggerCreatorParam

type LoggerCreatorParam interface {
	Apply(builder LoggerBuilder)
}

func Creator

func Creator(creator wlog.LoggerCreator) LoggerCreatorParam

func Extractor

func Extractor(extractor extractor.IDsFromRequest) LoggerCreatorParam

func ForbiddenHeaderParams

func ForbiddenHeaderParams(forbiddenParams ...string) LoggerCreatorParam

func ForbiddenPathParams

func ForbiddenPathParams(forbiddenParams ...string) LoggerCreatorParam

func ForbiddenQueryParams

func ForbiddenQueryParams(forbiddenParams ...string) LoggerCreatorParam

func SafeHeaderParams

func SafeHeaderParams(safeParams ...string) LoggerCreatorParam

func SafePathParams

func SafePathParams(safeParams ...string) LoggerCreatorParam

func SafeQueryParams

func SafeQueryParams(safeParams ...string) LoggerCreatorParam

type ParamPerms

type ParamPerms interface {
	// Safe returns true if the parameter with the provided name is safe to log. Case-insensitive.
	Safe(paramName string) bool
	// Forbidden returns true if the provided parameter is forbidden from being logged (that is, it should not be logged
	// at all, even as an unsafe parameter). Case-insensitive.
	Forbidden(paramName string) bool
}

func CombinedParamPerms

func CombinedParamPerms(perms ...ParamPerms) ParamPerms

func NewParamPerms

func NewParamPerms(safe, forbidden []string) ParamPerms

type Request

type Request struct {
	// Request is the *http.Request associated with the event.
	Request *http.Request
	// RouteInfo contains the path template and path parameter values for the request.
	RouteInfo RouteInfo
	// ResponseStatus is the status code of the response to the request.
	ResponseStatus int
	// ResponseSize is the size of the response to the request.
	ResponseSize int64
	// Duration is the total time it took to process the request.
	Duration time.Duration
	// PathParamPerms determines the path parameters that are safe and forbidden for logging.
	PathParamPerms ParamPerms
	// QueryParamPerms determines the query parameters that are safe and forbidden for logging.
	QueryParamPerms ParamPerms
	// HeaderParamPerms determines the header parameters that are safe and forbidden for logging.
	HeaderParamPerms ParamPerms
}

Request represents an HTTP request that has been (or is about to be) completed. Contains information on the request such as the request itself, the status code of the response, etc.

type RequestParamPerms

type RequestParamPerms interface {
	PathParamPerms() ParamPerms
	QueryParamPerms() ParamPerms
	HeaderParamPerms() ParamPerms
}

func DefaultRequestParamPerms

func DefaultRequestParamPerms() RequestParamPerms

type RouteInfo

type RouteInfo struct {
	Template   string
	PathParams map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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