Documentation
¶
Overview ¶
Package httplog provides HTTP request/response logging middleware. It supports separate request and response body logging, combined logging, and content-type filtering.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombinedLog ¶ added in v1.64.4
func CombinedLog(logger log.Logger, logBody bool) endpoint.LogMiddleware
CombinedLog creates a logging middleware that logs requests and responses in a single entry. If logBody is true, it logs request and response bodies for supported content types.
func Log ¶
func Log(logger log.Logger, logBody bool) endpoint.LogMiddleware
Log creates a logging middleware that logs requests and responses separately. If logBody is true, it logs request and response bodies for supported content types.
func LogWithOptions ¶
func LogWithOptions(logger log.Logger, opts ...Option) endpoint.LogMiddleware
LogWithOptions creates a logging middleware with custom configuration options. By default, body logging is disabled. Use options like WithLogBody, WithCombinedLog to customize the behavior.
func Noop ¶
func Noop() endpoint.LogMiddleware
Noop returns a no-operation logging middleware that simply passes through requests. It is useful as a placeholder or for testing when logging is not needed.
Types ¶
type Option ¶
type Option func(cfg *logConfig)
Option is a function that configures the logConfig.
func WithCombinedLog ¶ added in v1.64.4
WithCombinedLog enables or disables single combined log entry for request and response. When enabled, the middleware logs request and response in a single log entry instead of two separate entries.
func WithContentTypes ¶
WithContentTypes sets the content types for which request and response bodies will be logged. Content types are matched using prefix comparison (e.g., "application/json" matches "application/json; charset=utf-8").
func WithLogBody ¶
WithLogBody is a shortcut to enable both request and response body logging.
func WithLogRequestBody ¶
WithLogRequestBody enables or disables request body logging.
func WithLogResponseBody ¶
WithLogResponseBody enables or disables response body logging.