mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(common): log time with time zone
This commit is contained in:
@@ -86,7 +86,7 @@ require (
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230407102918-dd668c09f13d
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.0.1-0.20230327034731-79f520e7d373
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
|
||||
@@ -1172,8 +1172,9 @@ yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd h1:QUAIH9oqQoDRz/byjE
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd/go.mod h1:L5QYTYqiL+f56wzir14TWHurE3Vcn9elaFiQpPWhXsg=
|
||||
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
yunion.io/x/log v1.0.0 h1:VPgssPi8Om+KAHjlEjf6RDU86du//yO+X0upu+h6fZM=
|
||||
yunion.io/x/log v1.0.0/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361 h1:c5LyNdhbvBe/92pXs9jgXOU/S+RgYh/DHe538LpT/Mo=
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVBMeVzb3eDaYTxkVx9Kdo=
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
|
||||
@@ -330,6 +330,7 @@ func ParseOptions(optStruct interface{}, args []string, configFileName string, s
|
||||
}
|
||||
log.Infof("Set log level to %q", optionsRef.LogLevel)
|
||||
log.Logger().Formatter = &log.TextFormatter{
|
||||
TimeZone: optionsRef.TimeZone,
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
}
|
||||
if optionsRef.LogFilePrefix != "" {
|
||||
|
||||
Vendored
+1
-1
@@ -1521,7 +1521,7 @@ yunion.io/x/executor/server
|
||||
# yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/jsonutils
|
||||
# yunion.io/x/log v1.0.0
|
||||
# yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/log
|
||||
yunion.io/x/log/hooks
|
||||
|
||||
+10
-1
@@ -61,6 +61,8 @@ type TextFormatter struct {
|
||||
// Timestamp format to use for display when a full timestamp is printed.
|
||||
TimestampFormat string
|
||||
|
||||
TimeZone string
|
||||
|
||||
// The fields are sorted by default for a consistent output. For applications
|
||||
// that log extremely frequently and don't use the JSON formatter this may not
|
||||
// be desired.
|
||||
@@ -189,7 +191,14 @@ func (f *TextFormatter) printNoColored(b *bytes.Buffer, entry *logrus.Entry, key
|
||||
if f.ShortTimestamp {
|
||||
fmt.Fprintf(b, "[%s %04d %s]%s"+messageFormat, levelText, miniTS(), caller, prefix, message)
|
||||
} else {
|
||||
fmt.Fprintf(b, "[%s %s %s]%s"+messageFormat, levelText, entry.Time.Format(timestampFormat), caller, prefix, message)
|
||||
var tz *time.Location
|
||||
if len(f.TimeZone) > 0 {
|
||||
tz, _ = time.LoadLocation(f.TimeZone)
|
||||
}
|
||||
if tz == nil {
|
||||
tz = time.Local
|
||||
}
|
||||
fmt.Fprintf(b, "[%s %s %s]%s"+messageFormat, levelText, entry.Time.In(tz).Format(timestampFormat), caller, prefix, message)
|
||||
}
|
||||
for _, k := range keys {
|
||||
v := entry.Data[k]
|
||||
|
||||
Reference in New Issue
Block a user