Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions api/access_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package api

import (
"io"
"net/http"
"time"

"github.com/gorilla/handlers"
log "github.com/sirupsen/logrus"
)

func accessLogFormatter(_ io.Writer, params handlers.LogFormatterParams) {
if params.URL.Path == "/api/ping" {
return
}
Comment thread
abh marked this conversation as resolved.
Outdated
Comment thread
abh marked this conversation as resolved.
Outdated
log.WithFields(log.Fields{
"method": params.Request.Method,
"path": params.URL.Path,
"status": params.StatusCode,
"size": params.Size,
"duration": time.Since(params.TimeStamp).String(),
"remote": params.Request.RemoteAddr,
}).Info("http request")
}

func AccessLogMiddleware(next http.Handler) http.Handler {
return handlers.CustomLoggingHandler(nil, next, accessLogFormatter)
}
Comment thread
abh marked this conversation as resolved.
1 change: 1 addition & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func runService() {

var router http.Handler = route

router = api.AccessLogMiddleware(router)
router = handlers.ProxyHeaders(router)
Comment thread
abh marked this conversation as resolved.
Comment thread
abh marked this conversation as resolved.
http.Handle("/", router)

Expand Down
Loading