1
0
Fork 0

the LogMiddleware now produces less severe log enttries, which should keep the log more calm

Dieser Commit ist enthalten in:
Sebastian Tobie 2021-11-07 21:40:44 +01:00
Ursprung 6d43861ffc
Commit 327adffebf
1 geänderte Dateien mit 11 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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")
}()