debug

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSize = 1024

DefaultMaxSize is the default maximum size for a logged request or result value in bytes used by LogPayloads.

Variables

This section is empty.

Functions

func FormatJSON

func FormatJSON(_ context.Context, v any) string

FormatJSON returns a function that formats the given value as JSON.

func HTTP

func HTTP() func(http.Handler) http.Handler

HTTP returns a middleware that manages whether debug log entries are written. This middleware should be used in conjunction with the MountDebugLogEnabler function.

func LogPayloads

func LogPayloads(opts ...LogPayloadsOption) func(loom.Endpoint) loom.Endpoint

LogPayloads returns a Loom endpoint middleware that logs request payloads and response results using debug log entries.

Note: this middleware marshals the request and response data using the standard JSON marshaller. It only marshals if debug logs are enabled.

func MountDebugLogEnabler

func MountDebugLogEnabler(mux Muxer, opts ...DebugLogEnablerOption)

MountDebugLogEnabler mounts an endpoint under "/debug" that manages the status of debug logs. The endpoint accepts a single query parameter "debug-logs". If the parameter is set to "on" then debug logs are enabled. If the parameter is set to "off" then debug logs are disabled. In all other cases the endpoint returns the current debug logs status. The path, query parameter name and values can be changed using the WithPath, WithQuery, WithOnValue and WithOffValue options.

Note: the endpoint merely controls the status of debug logs. It does not actually configure the current logger. The logger is configured by the middleware returned by the HTTP function or by the gRPC interceptors returned by the UnaryServerInterceptor and StreamServerInterceptor functions which should be used in conjunction with the MountDebugLogEnabler function.

func MountPprofHandlers

func MountPprofHandlers(mux Muxer, opts ...PprofOption)

MountPprofHandlers mounts pprof handlers under /debug/pprof/. The list of mounted handlers is:

/debug/pprof/
/debug/pprof/allocs
/debug/pprof/block
/debug/pprof/cmdline
/debug/pprof/goroutine
/debug/pprof/heap
/debug/pprof/mutex
/debug/pprof/profile
/debug/pprof/symbol
/debug/pprof/threadcreate
/debug/pprof/trace

See the pprof package documentation for more information.

The path prefix ("/debug/pprof/") can be changed using WithPprofPrefix. Note: do not call this function on production servers accessible to the public! It exposes sensitive information about the server.

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a stream interceptor that manages whether debug log entries are written. Note: a change in the debug setting is effective only for the next stream request. This interceptor should be used in conjunction with the MountDebugLogEnabler function.

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor return an interceptor that manages whether debug log entries are written. This interceptor should be used in conjunction with the MountDebugLogEnabler function.

Types

type DebugLogEnablerOption

type DebugLogEnablerOption func(*dleOptions)

DebugLogEnablerOption is a function that applies a configuration option to MountDebugLogEnabler.

func WithOffValue

func WithOffValue(offval string) DebugLogEnablerOption

WithOffValue sets the query string parameter value used by MountDebugLogEnabler to disable debug logs.

func WithOnValue

func WithOnValue(onval string) DebugLogEnablerOption

WithOnValue sets the query string parameter value used by MountDebugLogEnabler to enable debug logs.

func WithPath

func WithPath(path string) DebugLogEnablerOption

WithPath sets the URL path used by MountDebugLogEnabler.

func WithQuery

func WithQuery(query string) DebugLogEnablerOption

WithQuery sets the query string parameter name used by MountDebugLogEnabler to enable or disable debug logs.

type FormatFunc

type FormatFunc func(context.Context, any) string

FormatFunc is used to format the logged value for payloads and results.

type LogPayloadsOption

type LogPayloadsOption func(*lpOptions)

LogPayloadsOption is a function that applies a configuration option to the LogPayloads middleware.

func WithClient

func WithClient() LogPayloadsOption

WithClient prefixes the log keys used by LogPayloads with "client-". This is useful when logging client requests and responses.

func WithFormat

func WithFormat(fn FormatFunc) LogPayloadsOption

WithFormat sets the log format used by LogPayloads.

func WithMaxSize

func WithMaxSize(n int) LogPayloadsOption

WithMaxSize sets the maximum size of a single log message or value used by LogPayloads.

type Muxer

type Muxer interface {
	http.Handler
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

Muxer is the HTTP mux interface used by the debug package.

func Adapt

func Adapt(m loomhttp.Muxer) Muxer

Adapt returns a debug.Muxer adapter for the given loomhttp.Muxer.

type PprofOption

type PprofOption func(*pprofOptions)

PprofOption is a function that applies a configuration option to MountPprofHandlers.

func WithPrefix

func WithPrefix(prefix string) PprofOption

WIthPrefix sets the path prefix used by MountPprofHandlers.

Jump to

Keyboard shortcuts

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