httplog

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClientAborted = errors.New("request aborted: client disconnected before response was sent")

Functions

func AttachError

func AttachError(ctx context.Context, err error) error

AttachError attaches the error attribute on the request log.

func AttachFields

func AttachFields(ctx context.Context, fields ...logger.Field)

AttachFields attaches the fields on the request log.

func Logging

func Logging(log *logger.Log, opts ...Option) func(http.Handler) http.Handler

Logging returns a gin.HandlerFunc (middleware) that logs requests using uber-go/logger.

Requests with errors are logged using logger.Error(). Requests without errors are logged using logger.Info().

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config logger/recover config

type Option

type Option func(c *Config)

Option logger/recover option

func WithEnableLogBody

func WithEnableLogBody(b bool) Option

WithEnableLogBody optional custom enable request/response body.

func WithExternalEnableLogBody

func WithExternalEnableLogBody(b *atomic.Bool) Option

WithExternalEnableLogBody optional custom enable request/response body control by external itself.

func WithLogBodyContentType

func WithLogBodyContentType(contentTypes []string) Option

WithLogBodyContentType optional custom record body content types.

func WithLogBodyLimit

func WithLogBodyLimit(limit int) Option

WithLogBodyLimit defines a list of body Content-Types that are safe to be logged. default: 4096, if <=0, mean not limit

func WithLogRecordRequestBody

func WithLogRecordRequestBody(f func(r *http.Request) bool) Option

WithLogRecordRequestBody optional custom skip request body logging option.

func WithLogRequestHeaders

func WithLogRequestHeaders(headers []string) Option

WithLogRequestHeaders optional custom record request headers.

func WithLogResponseBody

func WithLogResponseBody(f func(r *http.Request) bool) Option

WithLogResponseBody optional custom skip response body logging option.

func WithLogResponseHeaders

func WithLogResponseHeaders(headers []string) Option

WithLogResponseHeaders optional custom record response headers.

func WithSkipLogging

func WithSkipLogging(f func(r *http.Request) bool) Option

WithSkipLogging optional custom skip logging option.

Jump to

Keyboard shortcuts

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