dump 로직, 로깅 로직 개선

This commit is contained in:
Lectom C Han
2025-12-10 12:03:44 +09:00
parent 02a9734961
commit 766a43f2e4
2 changed files with 31 additions and 8 deletions

View File

@@ -129,12 +129,22 @@ func newFileLogger(path string) fiber.Handler {
return func(c *fiber.Ctx) error { return c.Next() }
}
format := "${time} ${ip} ${method} ${path} ${protocol} ${status} ${latency_human} headers=${reqHeaders}\n"
format := "${time} ip=${ip} real_ip=${header:X-Real-IP} forwarded=${header:X-Forwarded-For} ${method} ${path} ${protocol} ${status} ${latency_human} ua=\"${ua}\" headers=\"${reqHeadersShort}\"\n"
cfg := logger.Config{
Format: format,
TimeFormat: time.RFC3339,
TimeZone: "Asia/Seoul",
Output: writer,
CustomTags: map[string]logger.LogFunc{
"reqHeadersShort": func(output logger.Buffer, c *fiber.Ctx, data *logger.Data, param string) (int, error) {
const max = 1024
h := c.Request().Header.String()
if len(h) > max {
h = h[:max] + "...(truncated)"
}
return output.WriteString(strings.TrimSpace(h))
},
},
}
return logger.New(cfg)
}