fix: полный production-фикс fix40 (layout, sidebar, journald, логирование)

This commit is contained in:
2026-05-21 14:51:19 +05:00
parent 53711aecd3
commit 85798bebb6
19 changed files with 218 additions and 131 deletions
+20 -14
View File
@@ -18,26 +18,32 @@ func InitLog() {
LocalTime: true,
})
logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
logrus.SetLevel(logrus.WarnLevel)
logrus.SetLevel(logrus.InfoLevel)
}
func LogHandler() gin.HandlerFunc {
return func(c *gin.Context) {
startTime := time.Now()
endTime := time.Now()
statusCode := c.Writer.Status()
latencyTime := endTime.Sub(startTime)
clientIP := c.ClientIP()
reqMethod := c.Request.Method
reqUri := c.Request.RequestURI
logrus.WithFields(logrus.Fields{
"statusCode": statusCode,
"latencyTime": latencyTime,
"clientIP": clientIP,
"reqMethod": reqMethod,
"reqUri": reqUri,
}).Info()
c.Next()
statusCode := c.Writer.Status()
latencyTime := time.Since(startTime)
entry := logrus.WithFields(logrus.Fields{
"statusCode": statusCode,
"latencyTime": latencyTime.Milliseconds(),
"clientIP": c.ClientIP(),
"reqMethod": c.Request.Method,
"reqUri": c.Request.RequestURI,
})
if statusCode >= 500 {
entry.Error()
} else if statusCode >= 400 {
entry.Warn()
} else {
entry.Info()
}
}
}