diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 746a876..134a403 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,8 +2,6 @@ name: Lint on: push: - tags: - branches: pull_request: jobs: @@ -17,28 +15,6 @@ jobs: stable: false - uses: actions/checkout@v2 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: latest - - # Optional: working directory, useful for monorepos - working-directory: ./ - - # Optional: golangci-lint command line arguments. - args: --timeout 60s --max-same-issues 50 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true - - # optionally use a specific version of Go rather than the latest one - go_version: '1.21' + args: --timeout 120s --max-same-issues 50 diff --git a/README.md b/README.md index b717f13..9c5907f 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ router.GET("/pong", func(c *gin.Context) { router.Run(":1234") // output: -// time=2023-04-10T14:00:0.000000Z level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000Z +// time=2023-04-10T14:00:0.000000Z level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000Z ``` ### Filters @@ -158,7 +158,7 @@ router.GET("/pong", func(c *gin.Context) { router.Run(":1234") // output: -// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00" +// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00" ``` ### Using custom logger sub-group @@ -188,7 +188,7 @@ router.GET("/pong", func(c *gin.Context) { router.Run(":1234") // output: -// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" http.status=200 http.method=GET http.path=/pong http.ip=127.0.0.1 http.latency=20.125µs http.user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00 +// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" http.status=200 http.method=GET http.path=/pong http.route=/pong http.ip=127.0.0.1 http.latency=20.125µs http.user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00 ``` ### Add logger to a single route @@ -215,7 +215,7 @@ router.GET("/pong", sloggin.New(logger), func(c *gin.Context) { router.Run(":1234") // output: -// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00" +// time="2023-04-10 14:00:00" level=INFO msg="Incoming request" status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time="2023-04-10 14:00:00" ``` ### Adding custom attributes @@ -249,7 +249,7 @@ router.GET("/pong", func(c *gin.Context) { router.Run(":1234") // output: -// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" environment=production server=gin/1.9.0 gin_mode=release server_start_time=2023-04-10T10:00:00.000+02:00 status=200 method=GET path=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00 +// time=2023-04-10T14:00:0.000000+02:00 level=INFO msg="Incoming request" environment=production server=gin/1.9.0 gin_mode=release server_start_time=2023-04-10T10:00:00.000+02:00 status=200 method=GET path=/pong route=/pong ip=127.0.0.1 latency=25.5µs user-agent=curl/7.77.0 time=2023-04-10T14:00:00.000+02:00 ``` ### JSON output diff --git a/examples/example.go b/examples/example.go index e794035..2aecc15 100644 --- a/examples/example.go +++ b/examples/example.go @@ -38,6 +38,9 @@ func main() { router.GET("/pong", func(c *gin.Context) { c.String(http.StatusOK, "pong") }) + router.GET("/pong/:id", func(c *gin.Context) { + c.String(http.StatusOK, "pong") + }) logger.Info("Starting server") if err := router.Run(":1234"); err != nil { diff --git a/middleware.go b/middleware.go index 1cfadc5..c775df1 100644 --- a/middleware.go +++ b/middleware.go @@ -76,6 +76,7 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc { slog.Int("status", c.Writer.Status()), slog.String("method", c.Request.Method), slog.String("path", path), + slog.String("route", c.FullPath()), slog.String("ip", c.ClientIP()), slog.Duration("latency", latency), slog.String("user-agent", c.Request.UserAgent()),