-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add skip logging middleware by uri rule #1490
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipping some patterns is very useful! For this purpose, it would be good to use Skipper as suggested.
Additionally, we should modify some code in server.go
.
- e.Use(middlewares.Zerologger())
+ skipPatterns := []string{
+ "/tumblebug/api",
+ "/mcis?option=status",
+ }
+ e.Use(middlewares.Zerologger(skipPatterns))
func Zerologger() echo.MiddlewareFunc { | ||
return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Zerologger() echo.MiddlewareFunc { | |
return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ | |
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 | |
}, |
if skipLogging(v.URI) { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if skipLogging(v.URI) { | |
return nil | |
} |
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 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
} |
Thanks @yunkon-kim |
/approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seokho-son LGTM👍
Very first code ;)
skipPatterns should be injected from a higher level function.