From 52b4f8ca9180da9da9c2ccea2fe0718129412909 Mon Sep 17 00:00:00 2001 From: TonyWang Date: Sat, 20 Mar 2021 16:36:19 +0800 Subject: [PATCH] add timezone and timeformat (#572) * add timezone and timeformat * rm time zone and keep time format Co-authored-by: Tony Wang --- core/logx/config.go | 1 + core/logx/logs.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/logx/config.go b/core/logx/config.go index 41f52981..be09ae3a 100644 --- a/core/logx/config.go +++ b/core/logx/config.go @@ -4,6 +4,7 @@ package logx type LogConf struct { ServiceName string `json:",optional"` Mode string `json:",default=console,options=console|file|volume"` + TimeFormat string `json:",optional"` Path string `json:",default=logs"` Level string `json:",default=info,options=info|error|severe"` Compress bool `json:",optional"` diff --git a/core/logx/logs.go b/core/logx/logs.go index f185a1f4..98519315 100644 --- a/core/logx/logs.go +++ b/core/logx/logs.go @@ -20,6 +20,7 @@ import ( "github.com/tal-tech/go-zero/core/iox" "github.com/tal-tech/go-zero/core/sysx" "github.com/tal-tech/go-zero/core/timex" + ) const ( @@ -32,8 +33,6 @@ const ( ) const ( - timeFormat = "2006-01-02T15:04:05.000Z07" - accessFilename = "access.log" errorFilename = "error.log" severeFilename = "severe.log" @@ -64,6 +63,7 @@ var ( // ErrLogServiceNameNotSet is an error that indicates that the service name is not set. ErrLogServiceNameNotSet = errors.New("log service name must be set") + timeFormat = "2006-01-02T15:04:05.000Z07" writeConsole bool logLevel uint32 infoLog io.WriteCloser @@ -117,6 +117,9 @@ func MustSetup(c LogConf) { // we need to allow different service frameworks to initialize logx respectively. // the same logic for SetUp func SetUp(c LogConf) error { + if len(c.TimeFormat) > 0 { + timeFormat = c.TimeFormat + } switch c.Mode { case consoleMode: setupWithConsole(c)