Files
Microsoft-tts/internal/http/middleware/logger.go

29 lines
449 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"log"
"time"
"github.com/gin-gonic/gin"
)
// Logger 是一个HTTP中间件记录请求的详细信息
func Logger() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
// 处理请求
c.Next()
// 记录请求信息
duration := time.Since(start)
log.Printf("[%s] %s %s %d %s",
c.Request.Method,
c.Request.URL.Path,
c.ClientIP(),
c.Writer.Status(),
duration,
)
}
}