summaryrefslogtreecommitdiff
path: root/vendor/github.com/gin-gonic/gin/logger.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-05-21 13:17:22 +0000
committerLibravatar GitHub <noreply@github.com>2024-05-21 14:17:22 +0100
commit6c0d93c6cb082992fbc3c9bcbd85a99807563519 (patch)
treea9e86538cd911451bc927c304e1e20a68de00071 /vendor/github.com/gin-gonic/gin/logger.go
parent[chore]: Bump github.com/gin-contrib/cors from 1.7.1 to 1.7.2 (#2912) (diff)
downloadgotosocial-6c0d93c6cb082992fbc3c9bcbd85a99807563519.tar.xz
[chore] dependabot updates (#2922)
* [chore]: Bump github.com/prometheus/client_golang from 1.18.0 to 1.19.1 Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.18.0 to 1.19.1. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.1) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.0 to 0.6.1 Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.0 to 0.6.1. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.0...v0.6.1) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.20 to 2.20.24 Bumps [github.com/tdewolff/minify/v2](https://github.com/tdewolff/minify) from 2.20.20 to 2.20.24. - [Release notes](https://github.com/tdewolff/minify/releases) - [Commits](https://github.com/tdewolff/minify/compare/v2.20.20...v2.20.24) --- updated-dependencies: - dependency-name: github.com/tdewolff/minify/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/go-swagger/go-swagger Bumps [github.com/go-swagger/go-swagger](https://github.com/go-swagger/go-swagger) from 0.30.6-0.20240418033037-c46c303aaa02 to 0.31.0. - [Release notes](https://github.com/go-swagger/go-swagger/releases) - [Changelog](https://github.com/go-swagger/go-swagger/blob/master/.goreleaser.yml) - [Commits](https://github.com/go-swagger/go-swagger/commits/v0.31.0) --- updated-dependencies: - dependency-name: github.com/go-swagger/go-swagger dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/gin-gonic/gin from 1.9.1 to 1.10.0 Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.1 to 1.10.0. - [Release notes](https://github.com/gin-gonic/gin/releases) - [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md) - [Commits](https://github.com/gin-gonic/gin/compare/v1.9.1...v1.10.0) --- updated-dependencies: - dependency-name: github.com/gin-gonic/gin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/gin-gonic/gin/logger.go')
-rw-r--r--vendor/github.com/gin-gonic/gin/logger.go53
1 files changed, 32 insertions, 21 deletions
diff --git a/vendor/github.com/gin-gonic/gin/logger.go b/vendor/github.com/gin-gonic/gin/logger.go
index cd1e7fa6e..db2c6832b 100644
--- a/vendor/github.com/gin-gonic/gin/logger.go
+++ b/vendor/github.com/gin-gonic/gin/logger.go
@@ -47,8 +47,15 @@ type LoggerConfig struct {
// SkipPaths is an url path array which logs are not written.
// Optional.
SkipPaths []string
+
+ // Skip is a Skipper that indicates which logs should not be written.
+ // Optional.
+ Skip Skipper
}
+// Skipper is a function to skip logs based on provided Context
+type Skipper func(c *Context) bool
+
// LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
type LogFormatter func(params LogFormatterParams) string
@@ -83,6 +90,8 @@ func (p *LogFormatterParams) StatusCodeColor() string {
code := p.StatusCode
switch {
+ case code >= http.StatusContinue && code < http.StatusOK:
+ return white
case code >= http.StatusOK && code < http.StatusMultipleChoices:
return green
case code >= http.StatusMultipleChoices && code < http.StatusBadRequest:
@@ -239,32 +248,34 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
// Process request
c.Next()
- // Log only when path is not being skipped
- if _, ok := skip[path]; !ok {
- param := LogFormatterParams{
- Request: c.Request,
- isTerm: isTerm,
- Keys: c.Keys,
- }
-
- // Stop timer
- param.TimeStamp = time.Now()
- param.Latency = param.TimeStamp.Sub(start)
+ // Log only when it is not being skipped
+ if _, ok := skip[path]; ok || (conf.Skip != nil && conf.Skip(c)) {
+ return
+ }
- param.ClientIP = c.ClientIP()
- param.Method = c.Request.Method
- param.StatusCode = c.Writer.Status()
- param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String()
+ param := LogFormatterParams{
+ Request: c.Request,
+ isTerm: isTerm,
+ Keys: c.Keys,
+ }
- param.BodySize = c.Writer.Size()
+ // Stop timer
+ param.TimeStamp = time.Now()
+ param.Latency = param.TimeStamp.Sub(start)
- if raw != "" {
- path = path + "?" + raw
- }
+ param.ClientIP = c.ClientIP()
+ param.Method = c.Request.Method
+ param.StatusCode = c.Writer.Status()
+ param.ErrorMessage = c.Errors.ByType(ErrorTypePrivate).String()
- param.Path = path
+ param.BodySize = c.Writer.Size()
- fmt.Fprint(out, formatter(param))
+ if raw != "" {
+ path = path + "?" + raw
}
+
+ param.Path = path
+
+ fmt.Fprint(out, formatter(param))
}
}