Handle logger levels

This commit is contained in:
Dan Sosedoff
2022-12-01 12:49:24 -06:00
parent c996d71378
commit 72ecd20dd1
2 changed files with 14 additions and 3 deletions

View File

@@ -12,6 +12,8 @@ import (
const loggerMessage = "http_request"
func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
debug := logger.Level > logrus.InfoLevel
return func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
@@ -20,7 +22,7 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
c.Next()
// Skip logging static assets
if strings.Contains(path, "/static/") {
if strings.Contains(path, "/static/") && !debug {
return
}
@@ -40,6 +42,11 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
fields["error"] = err.Error()
}
// Additional fields for debugging
if debug {
fields["raw_query"] = c.Request.URL.RawQuery
}
entry := logrus.WithFields(fields)
switch {