feat: enhance log timestamp formatting with timezone support

This commit is contained in:
SunBK201 2025-11-02 02:06:12 +08:00
parent 8e649ca8b9
commit ec59323497

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"os" "os"
"strings" "strings"
"time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/sunbk201/ua3f/internal/config" "github.com/sunbk201/ua3f/internal/config"
@ -24,7 +25,11 @@ func (formatter *uctFormatter) Format(entry *logrus.Entry) ([]byte, error) {
} else { } else {
b = &bytes.Buffer{} 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)) b.WriteString(fmt.Sprintf("[%s][%s]: %s\n", formatTime, strings.ToUpper(entry.Level.String()), entry.Message))
return b.Bytes(), nil return b.Bytes(), nil
} }