Skip to content

Commit

Permalink
add timezone and timeformat (zeromicro#572)
Browse files Browse the repository at this point in the history
* add timezone and timeformat

* rm time zone and keep time format

Co-authored-by: Tony Wang <[email protected]>
  • Loading branch information
tonywangcn and tonywangca authored Mar 20, 2021
1 parent 4884a7b commit 52b4f8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/logx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 5 additions & 2 deletions core/logx/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -32,8 +33,6 @@ const (
)

const (
timeFormat = "2006-01-02T15:04:05.000Z07"

accessFilename = "access.log"
errorFilename = "error.log"
severeFilename = "severe.log"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52b4f8c

Please sign in to comment.