Documentation ¶
Index ¶
Constants ¶
View Source
const ( // ReqIDKey is a reference key to store a unique ID for each HTTP request within the context. // Use it to retreive the unique ID of a HTTP request in the wrapped handler from the request context. ReqIDKey ReqIDType = "reqid" // ReqIDKeyName is a reference slog key name that you can use to be consistent on how the key should be name. ReqIDKeyName string = "request_id" )
Variables ¶
View Source
var ( // DefaultBodyMaxRead is the default maximum number of bytes a body must have to be logged. // Its value is copied in the New() constructor. DefaultBodyMaxRead int64 = 10000 // DefaultSanitizeHeaders is the default list of headers to sanitize in the debug log. SanitizeHeaders = []string{"Authorization"} )
Functions ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a HTTP request/response logging utility. It wraps a slog.Logger and provides additional functionality for logging HTTP requests and responses. Instanciate with New().
func (*Logger) Log ¶
func (l *Logger) Log(next http.HandlerFunc) http.HandlerFunc
Log is a HTTP middleware that logs HTTP requests and responses. Use it to decorates your actual http handlers. Request body and response body are logged only if the wrapped slogger's level is set to LevelDebug or lower.
func (*Logger) TotalRequests ¶ added in v1.1.0
TotalRequests returns the number of requests that went thru the logger. Current, yet unfulfilled, requests are also taking into account.
Click to show internal directories.
Click to hide internal directories.