add timezone and timeformat (#572)
* add timezone and timeformat * rm time zone and keep time format Co-authored-by: Tony Wang <tonywang.data@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ package logx
|
|||||||
type LogConf struct {
|
type LogConf struct {
|
||||||
ServiceName string `json:",optional"`
|
ServiceName string `json:",optional"`
|
||||||
Mode string `json:",default=console,options=console|file|volume"`
|
Mode string `json:",default=console,options=console|file|volume"`
|
||||||
|
TimeFormat string `json:",optional"`
|
||||||
Path string `json:",default=logs"`
|
Path string `json:",default=logs"`
|
||||||
Level string `json:",default=info,options=info|error|severe"`
|
Level string `json:",default=info,options=info|error|severe"`
|
||||||
Compress bool `json:",optional"`
|
Compress bool `json:",optional"`
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/tal-tech/go-zero/core/iox"
|
"github.com/tal-tech/go-zero/core/iox"
|
||||||
"github.com/tal-tech/go-zero/core/sysx"
|
"github.com/tal-tech/go-zero/core/sysx"
|
||||||
"github.com/tal-tech/go-zero/core/timex"
|
"github.com/tal-tech/go-zero/core/timex"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,8 +33,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
timeFormat = "2006-01-02T15:04:05.000Z07"
|
|
||||||
|
|
||||||
accessFilename = "access.log"
|
accessFilename = "access.log"
|
||||||
errorFilename = "error.log"
|
errorFilename = "error.log"
|
||||||
severeFilename = "severe.log"
|
severeFilename = "severe.log"
|
||||||
@@ -64,6 +63,7 @@ var (
|
|||||||
// ErrLogServiceNameNotSet is an error that indicates that the service name is not set.
|
// ErrLogServiceNameNotSet is an error that indicates that the service name is not set.
|
||||||
ErrLogServiceNameNotSet = errors.New("log service name must be set")
|
ErrLogServiceNameNotSet = errors.New("log service name must be set")
|
||||||
|
|
||||||
|
timeFormat = "2006-01-02T15:04:05.000Z07"
|
||||||
writeConsole bool
|
writeConsole bool
|
||||||
logLevel uint32
|
logLevel uint32
|
||||||
infoLog io.WriteCloser
|
infoLog io.WriteCloser
|
||||||
@@ -117,6 +117,9 @@ func MustSetup(c LogConf) {
|
|||||||
// we need to allow different service frameworks to initialize logx respectively.
|
// we need to allow different service frameworks to initialize logx respectively.
|
||||||
// the same logic for SetUp
|
// the same logic for SetUp
|
||||||
func SetUp(c LogConf) error {
|
func SetUp(c LogConf) error {
|
||||||
|
if len(c.TimeFormat) > 0 {
|
||||||
|
timeFormat = c.TimeFormat
|
||||||
|
}
|
||||||
switch c.Mode {
|
switch c.Mode {
|
||||||
case consoleMode:
|
case consoleMode:
|
||||||
setupWithConsole(c)
|
setupWithConsole(c)
|
||||||
|
|||||||
Reference in New Issue
Block a user