Skip to content

Commit

Permalink
Bring skip pattern as param
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son committed Apr 3, 2024
1 parent af710f5 commit 28c5c5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src/api/rest/server/middlewares/custom-middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ import (
"github.com/rs/zerolog/log"
)

func skipLogging(uri string) bool {
skipPatterns := []string{
"/tumblebug/api",
"/mcis?option=status",
}

for _, pattern := range skipPatterns {
if strings.Contains(uri, pattern) {
return true
}
}
return false
}

func Zerologger() echo.MiddlewareFunc {
func Zerologger(skipPatterns []string) echo.MiddlewareFunc {
return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
Skipper: func(c echo.Context) bool {
for _, pattern := range skipPatterns {
if strings.Contains(c.Request().URL.Path, pattern) {
return true
}
}
return false
},
LogError: true,
LogRequestID: true,
LogRemoteIP: true,
Expand All @@ -41,9 +35,6 @@ func Zerologger() echo.MiddlewareFunc {
LogResponseSize: true,
// HandleError: true, // forwards error to the global error handler, so it can decide appropriate status code
LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
if skipLogging(v.URI) {
return nil
}
if v.Error == nil {
log.Info().
Str("id", v.RequestID).
Expand Down
7 changes: 6 additions & 1 deletion src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func RunServer(port string) {

// Middleware
// e.Use(middleware.Logger())
e.Use(middlewares.Zerologger())
APILogSkipPatterns := []string{
"/tumblebug/api",
"/mcis?option=status",
}
e.Use(middlewares.Zerologger(APILogSkipPatterns))

e.Use(middleware.Recover())
// limit the application to 20 requests/sec using the default in-memory store
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))
Expand Down

0 comments on commit 28c5c5d

Please sign in to comment.