httplog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httplog traces and logs the requests a net/http server answers, with the logs set up by the telemetry package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(handler http.Handler, serviceName string, options Options) http.Handler

Handler returns handler, tracing each request and logging it at the level for how it ended. The line has the route that matched (http.route) when handler is the http.ServeMux itself, which sets it on the request.

func LogAttrs

func LogAttrs(request *http.Request, attrs ...slog.Attr)

LogAttrs adds attrs, such as the signed-in user's id, to the records written with the request's context from now on, and to the line the request is logged with

Types

type Options

type Options struct {
	// Levels are the levels requests are logged at, by how they ended
	Levels telemetry.RequestLevels
	// Public ignores the trace id a caller sends, so each request starts its own trace
	Public bool
	// Path is what a request's path is logged as, such as with an email address
	// in it replaced. The path itself when nil.
	Path func(*http.Request) string
	// OnPanic answers a request whose handler panicked, after the panic is
	// logged, unless the handler had started its answer. A plain 500 when nil.
	OnPanic func(http.ResponseWriter)
}

Options are how Handler traces and logs requests

Jump to

Keyboard shortcuts

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