the LogMiddleware now produces less severe log enttries, which should keep the log more calm
Dieser Commit ist enthalten in:
Ursprung
6d43861ffc
Commit
327adffebf
|
@ -19,19 +19,24 @@ func LogMiddleware(c *gin.Context) {
|
|||
var xid = log.NewXIDWithTime(time.Now().UnixNano())
|
||||
c.Set("xid", xid)
|
||||
defer func() {
|
||||
var entry = log.Info()
|
||||
int := recover()
|
||||
if int != nil {
|
||||
err := int.(error)
|
||||
var entry *log.Entry
|
||||
interrupt := recover()
|
||||
if interrupt != nil {
|
||||
err := interrupt.(error)
|
||||
c.Header("requestid", xid.String())
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
entry = log.Error().Err(err).Int("statuscode", 500)
|
||||
} else {
|
||||
statuscode := c.Writer.Status()
|
||||
if statuscode >= 400 {
|
||||
switch {
|
||||
case statuscode >= 400 && statuscode < 500:
|
||||
entry = log.Warn()
|
||||
case statuscode >= 500:
|
||||
entry = log.Error()
|
||||
default:
|
||||
entry = log.Info()
|
||||
}
|
||||
entry = entry.Int("statuscode", statuscode)
|
||||
entry.Int("statuscode", statuscode)
|
||||
}
|
||||
entry.Int64("goroutine", log.Goid()).Xid("ID", xid).Msg("Request")
|
||||
}()
|
||||
|
|
Laden…
In neuem Issue referenzieren