Documentation
¶
Index ¶
- Constants
- func FormatJSON(_ context.Context, v interface{}) string
- func HTTP() func(http.Handler) http.Handler
- func LogPayloads(opts ...LogPayloadsOption) func(goa.Endpoint) goa.Endpoint
- func MountDebugLogEnabler(mux Muxer, opts ...DebugLogEnablerOption)
- func MountPprofHandlers(mux Muxer, opts ...PprofOption)
- func StreamServerInterceptor() grpc.StreamServerInterceptor
- func UnaryServerInterceptor() grpc.UnaryServerInterceptor
- type DebugLogEnablerOption
- type FormatFunc
- type LogPayloadsOption
- type Muxer
- type PprofOption
Constants ¶
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 ¶
FormatJSON returns a function that formats the given value as JSON.
func HTTP ¶ added in v0.16.0
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(goa.Endpoint) goa.Endpoint
LogPayloads returns a Goa 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 ¶ added in v0.16.0
type DebugLogEnablerOption func(*dleOptions)
DebugLogEnablerOption is a function that applies a configuration option to MountDebugLogEnabler.
func WithOffValue ¶ added in v0.16.0
func WithOffValue(offval string) DebugLogEnablerOption
WithOffValue sets the query string parameter value used by MountDebugLogEnabler to disable debug logs.
func WithOnValue ¶ added in v0.16.0
func WithOnValue(onval string) DebugLogEnablerOption
WithOnValue sets the query string parameter value used by MountDebugLogEnabler to enable debug logs.
func WithPath ¶ added in v0.16.0
func WithPath(path string) DebugLogEnablerOption
WithPath sets the URL path used by MountDebugLogEnabler.
func WithQuery ¶ added in v0.16.0
func WithQuery(query string) DebugLogEnablerOption
WithQuery sets the query string parameter name used by MountDebugLogEnabler to enable or disable debug logs.
type FormatFunc ¶
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 ¶ added in v0.15.1
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.
type PprofOption ¶ added in v0.16.0
type PprofOption func(*pprofOptions)
PprofOption is a function that applies a configuration option to MountPprofHandlers.
func WithPrefix ¶ added in v0.16.0
func WithPrefix(prefix string) PprofOption
WIthPrefix sets the path prefix used by MountPprofHandlers.