Documentation ¶
Overview ¶
Package httplog contains a helper object and functions to maintain a log along with an http response.
Index ¶
- func DefaultStacktracePred(status int) bool
- func Handler(delegate http.Handler, pred StacktracePred) http.Handler
- func LogOf(w http.ResponseWriter) *respLogger
- func NewLogged(req *http.Request, w *http.ResponseWriter) *respLogger
- func Unlogged(w http.ResponseWriter) http.ResponseWriter
- type StacktracePred
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultStacktracePred ¶
DefaultStacktracePred is the default implementation of StacktracePred.
func Handler ¶
func Handler(delegate http.Handler, pred StacktracePred) http.Handler
Handler wraps all HTTP calls to delegate with nice logging. delegate may use LogOf(w).Addf(...) to write additional info to the per-request log message.
Intended to wrap calls to your ServeMux.
func LogOf ¶
func LogOf(w http.ResponseWriter) *respLogger
LogOf returns the logger hiding in w. Panics if there isn't such a logger, because NewLogged() must have been previously called for the log to work.
func NewLogged ¶
func NewLogged(req *http.Request, w *http.ResponseWriter) *respLogger
NewLogged turns a normal response writer into a logged response writer.
Usage:
defer NewLogged(req, &w).StacktraceWhen(StatusIsNot(200, 202)).Log()
(Only the call to Log() is defered, so you can set everything up in one line!)
Note that this *changes* your writer, to route response writing actions through the logger.
Use LogOf(w).Addf(...) to log something along with the response result.
func Unlogged ¶
func Unlogged(w http.ResponseWriter) http.ResponseWriter
Unlogged returns the original ResponseWriter, or w if it is not our inserted logger.
Types ¶
type StacktracePred ¶
StacktracePred returns true if a stacktrace should be logged for this status
func StatusIsNot ¶
func StatusIsNot(statuses ...int) StacktracePred
StatusIsNot returns a StacktracePred which will cause stacktraces to be logged for any status *not* in the given list.