Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions route/access_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package route

import (
"strings"

echo_middleware "github.com/labstack/echo/v4/middleware"
)

// accessLogFormat is echo's default access log with the path in place of the
// request URI: websocket routes take the user's token from the query string
// (a browser cannot set a header on a websocket), and it must not reach the
// journal.
var accessLogFormat = strings.Replace(echo_middleware.DefaultLoggerConfig.Format, `"uri":"${uri}"`, `"path":"${path}"`, 1)
12 changes: 12 additions & 0 deletions route/access_log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package route

import (
"strings"
"testing"
)

func TestTheAccessLogLeavesTheQueryStringOut(t *testing.T) {
if strings.Contains(accessLogFormat, "${uri}") || !strings.Contains(accessLogFormat, "${path}") {
t.Fatalf("the access log must log the path, not the URI with its query: %s", accessLogFormat)
}
}
2 changes: 1 addition & 1 deletion route/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func InitV1Router() http.Handler {

e.Use(echo_middleware.Gzip())
e.Use(echo_middleware.Recover())
e.Use(echo_middleware.Logger())
e.Use(echo_middleware.LoggerWithConfig(echo_middleware.LoggerConfig{Format: accessLogFormat}))

v1Group := e.Group("/v1")

Expand Down
2 changes: 1 addition & 1 deletion route/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func InitV2Router() http.Handler {

e.Use(echo_middleware.Gzip())

e.Use(echo_middleware.Logger())
e.Use(echo_middleware.LoggerWithConfig(echo_middleware.LoggerConfig{Format: accessLogFormat}))

e.Use(echojwt.WithConfig(echojwt.Config{
Skipper: func(c echo.Context) bool {
Expand Down
Loading