完善非成功请求的日志处理

This commit is contained in:
2025-05-09 15:06:22 +08:00
parent 7c684ca0ad
commit 189f523693
2 changed files with 18 additions and 12 deletions

View File

@@ -114,6 +114,11 @@ func useLogger() fiber.Handler {
Format: "🚀 ${time} | ${locals:authtype} ${locals:authid} | ${method} ${path} | ${status} | ${latency} | ${error}\n",
TimeFormat: "2006-01-02 15:04:05",
TimeZone: "Asia/Shanghai",
Next: func(c *fiber.Ctx) bool {
c.Locals("authtype", auth.PayloadNone.ToStr())
c.Locals("authid", 0)
return false
},
Done: func(c *fiber.Ctx, logBytes []byte) {
var logStr = strings.TrimPrefix(string(logBytes), "🚀")
var logVars = strings.Split(logStr, "|")
@@ -147,8 +152,8 @@ func useLogger() fiber.Handler {
Error: errStr,
Time: core.LocalDateTime(reqTime),
}
if authType != nil {
item.Identity = int32(*authType)
if authType != auth.PayloadNone {
item.Identity = int32(authType)
}
if authID != 0 {
item.Visitor = int32(authID)