Skip to content
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

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

seokho-son
Copy link
Member

Very first code ;)
skipPatterns should be injected from a higher level function.

Copy link
Member

@yunkon-kim yunkon-kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son

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))

Comment on lines 29 to 30
func Zerologger() echo.MiddlewareFunc {
return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
},

Comment on lines 44 to 46
if skipLogging(v.URI) {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if skipLogging(v.URI) {
return nil
}

Comment on lines 15 to 28
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
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}

@seokho-son
Copy link
Member Author

Thanks @yunkon-kim
Applied your suggestion! Super nice.

@seokho-son
Copy link
Member Author

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Apr 3, 2024
@cb-github-robot cb-github-robot merged commit 15c5ebd into cloud-barista:main Apr 3, 2024
3 checks passed
Copy link
Member

@yunkon-kim yunkon-kim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son LGTM👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This PR is approved and will be merged soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants