1package negroni
2
3import (
4	"log"
5	"net/http"
6	"os"
7	"time"
8)
9
10// Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
11type Logger struct {
12	// Logger inherits from log.Logger used to log messages with the Logger middleware
13	*log.Logger
14}
15
16// NewLogger returns a new Logger instance
17func NewLogger() *Logger {
18	return &Logger{log.New(os.Stdout, "[negroni] ", 0)}
19}
20
21func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
22	start := time.Now()
23	l.Printf("Started %s %s", r.Method, r.URL.Path)
24
25	next(rw, r)
26
27	res := rw.(ResponseWriter)
28	l.Printf("Completed %v %s in %v", res.Status(), http.StatusText(res.Status()), time.Since(start))
29}
30