[add] username in http access logs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Evan Reichard 2024-01-09 21:36:36 -05:00
parent 8a8f12c07a
commit 14b930781e

View File

@ -247,8 +247,26 @@ func apiLogger() gin.HandlerFunc {
endTime := time.Now() endTime := time.Now()
latency := endTime.Sub(startTime).Round(time.Microsecond) latency := endTime.Sub(startTime).Round(time.Microsecond)
// Get Username
var auth authData
if data, _ := c.Get("Authorization"); data != nil {
auth = data.(authData)
}
username := auth.UserName
if username != "" {
username = " (" + username + ")"
}
// Log Result // Log Result
log.Infof("[HTTPRouter] %-15s (%10s) %d %7s %s", c.ClientIP(), latency, c.Writer.Status(), c.Request.Method, c.Request.URL.Path) log.Infof("[HTTPRouter] %-15s (%10s) %d %7s %s%s",
c.ClientIP(),
latency,
c.Writer.Status(),
c.Request.Method,
c.Request.URL.Path,
username,
)
} }
} }