httplog

package
v0.8.12 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Duration            = "duration" // In nanoseconds
	HTTPStatusCode      = "http.status_code"
	HTTPMethod          = "http.method"
	HTTPURLDetailsPath  = "http.url_details.path"
	NetworkBytesRead    = "network.bytes_read"
	NetworkBytesWritten = "network.bytes_written"
	Operation           = "op"
	Request             = "request"
	RequestID           = "http.request_id"
	RequestHeaders      = "request.headers"
	RequestError        = "request.body_error"
	Response            = "response"
	TraceID             = "trace_id"
	UserID              = "usr.id"
)

Reference: https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#http-requests

Variables

View Source
var ErrInternal = errors.New("internal error")

ErrInternal is the default error returned from a panic.

View Source
var MaxBodyLog uint32 = 24 * 1024

MaxBodyLog controls the maximum request/response body that can be logged. Anything greater will be truncated.

View Source
var RecoverBasePath = initBasePath()

Functions

func LogRecoverError added in v0.4.9

func LogRecoverError(ctx context.Context, stackSkip int, recoverErr any)

func RecoverLogger added in v0.3.3

func RecoverLogger(log zerolog.Logger) func(http.Handler) http.Handler

RecoverLogger injects log into requests context and handles panic recovery and logging with stack.

func RequestLogger

func RequestLogger(shouldLog FnShouldLog) func(http.Handler) http.Handler

RequestLogger logs optional data, as specified by the shouldLog func. NOTE: The zerolog context logger MUST be initialized prior to this handler invocation. This is generally done by using the recover logger, or by using the zerolog/hlog.NewHandler directly.

func SimplifyStack added in v0.4.9

func SimplifyStack(stack string, skip int) []string

func StatusToLogLevel added in v0.8.0

func StatusToLogLevel(_ *http.Request, status int) zerolog.Level

Types

type FnShouldLog

type FnShouldLog func(r *http.Request) (logRequest, logRequestBody, logResponseBody bool, toLogLevel FnToLogLevel)

FnShouldLog given a request, return flags that control logging. logRequest will disable the entire request logging middleware, default is true. logRequestBody will log the body of the request, default is false. logResponseBody will log the body of the response, default is false. This should be disabled for large or streaming results.

type FnToLogLevel added in v0.8.0

type FnToLogLevel func(r *http.Request, status int) zerolog.Level

func LogAll added in v0.3.3

func LogAll(_ *http.Request) (bool, bool, bool, FnToLogLevel)

func LogRequestBody added in v0.3.3

func LogRequestBody(_ *http.Request) (bool, bool, bool, FnToLogLevel)

Jump to

Keyboard shortcuts

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