dump 로직, 로깅 로직 개선
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ func scanRow(rows *sql.Rows) ([]string, error) {
|
||||
userCompany sql.NullString
|
||||
userDepartment sql.NullString
|
||||
userPosition sql.NullString
|
||||
userLoginTime sql.NullTime
|
||||
createdAt sql.NullTime
|
||||
userLoginTime sql.NullString
|
||||
createdAt sql.NullString
|
||||
userFamilyFlag sql.NullString
|
||||
)
|
||||
|
||||
@@ -225,8 +225,8 @@ func scanRow(rows *sql.Rows) ([]string, error) {
|
||||
nullToString(userCompany),
|
||||
nullToString(userDepartment),
|
||||
nullToString(userPosition),
|
||||
formatTimestamp(userLoginTime),
|
||||
formatTimestamp(createdAt),
|
||||
formatTimestamp(userLoginTime.String),
|
||||
formatTimestamp(createdAt.String),
|
||||
nullToString(userFamilyFlag),
|
||||
}, nil
|
||||
}
|
||||
@@ -242,9 +242,22 @@ func netAddr(host string, port int) string {
|
||||
return fmt.Sprintf("%s:%d", host, port)
|
||||
}
|
||||
|
||||
func formatTimestamp(t sql.NullTime) string {
|
||||
if !t.Valid {
|
||||
func formatTimestamp(raw string) string {
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
return t.Time.In(kst()).Format("2006-01-02 15:04:05.000")
|
||||
for _, layout := range []string{
|
||||
"2006-01-02 15:04:05.000",
|
||||
"2006-01-02 15:04:05",
|
||||
time.RFC3339,
|
||||
"2006-01-02T15:04:05.000Z07:00",
|
||||
} {
|
||||
if t, err := time.Parse(layout, raw); err == nil {
|
||||
return t.In(kst()).Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
if t, err := time.ParseInLocation(layout, raw, kst()); err == nil {
|
||||
return t.In(kst()).Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user