mirror of
https://gitee.com/mirrors/AllinSSL.git
synced 2026-03-08 15:51:11 +08:00
Add files via upload
This commit is contained in:
37
backend/middleware/log.go
Normal file
37
backend/middleware/log.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"ALLinSSL/backend/public"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func LoggerMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
c.Next()
|
||||
|
||||
duration := time.Since(start)
|
||||
method := c.Request.Method
|
||||
path := c.Request.URL.Path
|
||||
status := c.Writer.Status()
|
||||
clientIP := c.ClientIP()
|
||||
userAgent := c.Request.UserAgent()
|
||||
respSize := c.Writer.Size() // 响应体字节大小
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"| %3d | %13v | %15s | %-7s %-30s | UA: %-40s | RespSize: %d bytes",
|
||||
status,
|
||||
duration,
|
||||
clientIP,
|
||||
method,
|
||||
path,
|
||||
userAgent,
|
||||
respSize,
|
||||
)
|
||||
|
||||
public.Info(msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user