You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
803 B

package app
import (
type loggingResponseWriter struct {
statusCode int
// mimic ResponseWriter's WriteHeader to capture the code
func (lrw *loggingResponseWriter) WriteHeader(code int) {
lrw.statusCode = code
// Logs ip (for those pingback bad boys to put in jail), request url, method, and response status code.
func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logWriter := &loggingResponseWriter{w, http.StatusOK}
next.ServeHTTP(logWriter, r)
Str("url", r.RequestURI).
Str("ip", ipFrom(r)).
Str("method", r.Method).
Int("status", logWriter.statusCode).