From b6e43e87f02ed4e5de0f7a8085c4a78bcd7e0220 Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Sun, 2 Nov 2025 02:06:12 +0800 Subject: [PATCH] feat: enhance log timestamp formatting with timezone support --- src/internal/log/log.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal/log/log.go b/src/internal/log/log.go index 88e842c..75eddb1 100644 --- a/src/internal/log/log.go +++ b/src/internal/log/log.go @@ -6,6 +6,7 @@ import ( "io" "os" "strings" + "time" "github.com/sirupsen/logrus" "github.com/sunbk201/ua3f/internal/config" @@ -24,7 +25,11 @@ func (formatter *uctFormatter) Format(entry *logrus.Entry) ([]byte, error) { } else { b = &bytes.Buffer{} } - formatTime := entry.Time.Format("2006-01-02 15:04:05") + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + loc = time.FixedZone("CST", 8*3600) + } + formatTime := entry.Time.In(loc).Format("2006-01-02 15:04:05") b.WriteString(fmt.Sprintf("[%s][%s]: %s\n", formatTime, strings.ToUpper(entry.Level.String()), entry.Message)) return b.Bytes(), nil }