mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 14:18:46 +00:00
30 lines
801 B
Go
30 lines
801 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/runatlantis/atlantis/server/logging"
|
|
"github.com/urfave/negroni"
|
|
)
|
|
|
|
// NewRequestLogger creates a RequestLogger.
|
|
func NewRequestLogger(logger *logging.SimpleLogger) *RequestLogger {
|
|
return &RequestLogger{logger}
|
|
}
|
|
|
|
// RequestLogger logs requests and their response codes.
|
|
type RequestLogger struct {
|
|
logger *logging.SimpleLogger
|
|
}
|
|
|
|
// ServeHTTP implements the middleware function. It logs a request at INFO
|
|
// level unless it's a request to /static/*.
|
|
func (l *RequestLogger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
next(rw, r)
|
|
res := rw.(negroni.ResponseWriter)
|
|
if !strings.HasPrefix(r.URL.RequestURI(), "/static") {
|
|
l.logger.Info("%d | %s %s", res.Status(), r.Method, r.URL.RequestURI())
|
|
}
|
|
}
|