Documentation ¶
Index ¶
- func AppendAccessLog(req *http.Request, f AccessLogCallback)
- func AppendAccessLogContext(ctx context.Context, f AccessLogCallback)
- func DontLog(req *http.Request)
- func LoggingMiddleware(opts ...LoggingOption) func(http.Handler) http.Handler
- func RecoveryMiddleware(next http.Handler) http.Handler
- func SetupLogging(levelName, logFile string) error
- func StripPort(clientIP string) string
- func WriteUnhandledError(w http.ResponseWriter, req *http.Request, err error, traceback string)
- type AccessLogCallback
- type Logger
- func (l *Logger) CloseNotify() <-chan bool
- func (l *Logger) Flush()
- func (l *Logger) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (l *Logger) Length() int64
- func (l *Logger) Push(target string, opts *http.PushOptions) error
- func (l *Logger) Started() time.Time
- func (l *Logger) Status() int
- func (l *Logger) Write(d []byte) (size int, err error)
- func (l *Logger) WriteHeader(status int)
- type LoggingOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendAccessLog ¶
func AppendAccessLog(req *http.Request, f AccessLogCallback)
AppendAccessLog adds a callback function which will be invoked to amend the access log with additional fields.
func AppendAccessLogContext ¶
func AppendAccessLogContext(ctx context.Context, f AccessLogCallback)
AppendAccessLog adds a callback function which will be invoked to amend the access log with additional fields.
func LoggingMiddleware ¶
func LoggingMiddleware(opts ...LoggingOption) func(http.Handler) http.Handler
LoggingMiddleware creates a logging context for each request, and emits an access log entry at the completion of the request.
func RecoveryMiddleware ¶
RecoveryMiddleware catches panics, logs the error, and writes a generic Internal Server Error response
func SetupLogging ¶
SetupLogging initializes zerolog with reasonable defaults
func WriteUnhandledError ¶
WriteUnhandledError writes a generic 500 Internal Server Error response while logging the actual unhandled error and optional traceback
Types ¶
type AccessLogCallback ¶
type Logger ¶
type Logger struct { http.ResponseWriter Now func() time.Time // contains filtered or unexported fields }
Logger wraps a ResponseWriter and records the resulting status code and how many bytes are written
func (*Logger) CloseNotify ¶
CloseNotify wraps a nested CloseNotifier
func (*Logger) Push ¶
func (l *Logger) Push(target string, opts *http.PushOptions) error
Push wraps a nested Pusher
func (*Logger) WriteHeader ¶
WriteHeader implements ResponseWriter
type LoggingOption ¶
type LoggingOption func(*loggingConfig)
func WithLogger ¶
func WithLogger(logger zerolog.Logger) LoggingOption
WithLogger sets the base logger for the middleware