This commit is contained in:
oneao committed 2025-08-12 17:28:23 +08:00
1 parent 1fd0697aee
commit 9af3234672
13 files changed
+358 -26

No files matched your search

@@ -2,14 +2,18 @@ package middleware
import (
"base-framework/pkg/router"
"log"
"time"
)
func Logger() router.HandlerFunc {
return func(c *router.Context) {
start := time.Now()
// 执行后续中间件和处理器
c.Next()
log.Printf("[%s] %s in %v", c.Request.Method, c.Request.URL.Path, time.Since(start))
elapsed := time.Since(start)
// 即使业务中断,这里也能执行,打印耗时
path := c.Request.URL.Path
method := c.Request.Method
println(method, path, "耗时:", elapsed.String())
}
}