Skip to content

Commit

Permalink
feat: gin access log add exclude path
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdu2009 committed Oct 28, 2019
1 parent fe2ba6a commit f552fbd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/gomodule/redigo v2.0.0+incompatible
github.com/leodido/go-urn v1.1.0 // indirect
github.com/nickxb/gin-http-logger v0.0.0-20190523055149-762fe88a7fa4
github.com/nickxb/gin-http-logger v1.1.1-0.20191028062356-c63c682255f4
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
gopkg.in/go-playground/validator.v9 v9.28.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nickxb/gin-http-logger v0.0.0-20190523055149-762fe88a7fa4 h1:nXwOIGLh6rxIxtmEUX8+NSd5JKtTWHz9NoD8qOhFPMk=
github.com/nickxb/gin-http-logger v0.0.0-20190523055149-762fe88a7fa4/go.mod h1:x9H4fWPQ7atgzXuYGWh3MT/JoWP05Znnz9SgTwxeArU=
github.com/nickxb/gin-http-logger v1.1.1-0.20191028062356-c63c682255f4 h1:fk4PMF0STJnoCrwBAUIScOhJRfgmxpaPcWtEoAzSL7Y=
github.com/nickxb/gin-http-logger v1.1.1-0.20191028062356-c63c682255f4/go.mod h1:5C1/EWTLeUabG+97z49M9MbFJE0LP07a9VlfSqlyk/4=
github.com/nickxb/gin-http-logger v2.0.2+incompatible h1:MXlWZnzi2vjT+/iiKHfAuXoj2rZ/IVcm8bKjaTA3iiE=
github.com/nickxb/gin-http-logger v2.0.2+incompatible/go.mod h1:U/v8B2W5hUoARNdceiMKs6YG3zsI1VxuA9uH4B33/7I=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
12 changes: 9 additions & 3 deletions xgin/access_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package xgin

import (
"fmt"
httpLogger "github.com/nickxb/gin-http-logger"
"os"

"github.com/gin-gonic/gin"
httpLogger "github.com/nickxb/gin-http-logger"
"github.com/sirupsen/logrus"
"os"
)

func AccessLogger(file string, level string) gin.HandlerFunc {
func AccessLogger(file string, level string, excludePaths ...string) gin.HandlerFunc {
accessLogger := logrus.New()
accessLogger.SetFormatter(&logrus.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05.000",
Expand All @@ -33,5 +34,10 @@ func AccessLogger(file string, level string) gin.HandlerFunc {
DropSize: 1024 * 10, //10k
}

alc.ExcludePaths = map[string]bool{}
for _, excludePath := range excludePaths {
alc.ExcludePaths[excludePath] = true
}

return httpLogger.New(alc)
}

0 comments on commit f552fbd

Please sign in to comment.