[add] username in http access logs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8a8f12c07a
commit
14b930781e
20
api/api.go
20
api/api.go
@ -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,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user