mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
Add custom log file name date format (#4333)
This commit is contained in:
parent
29400f6814
commit
075817a8dd
@ -42,4 +42,6 @@ type LogConf struct {
|
|||||||
// daily: daily rotation.
|
// daily: daily rotation.
|
||||||
// size: size limited rotation.
|
// size: size limited rotation.
|
||||||
Rotation string `json:",default=daily,options=[daily,size]"`
|
Rotation string `json:",default=daily,options=[daily,size]"`
|
||||||
|
// FileTimeFormat represents the time format for file name, default is `2006-01-02T15:04:05.000Z07:00`.
|
||||||
|
FileTimeFormat string `json:",optional"`
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,10 @@ func SetUp(c LogConf) (err error) {
|
|||||||
timeFormat = c.TimeFormat
|
timeFormat = c.TimeFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.FileTimeFormat) > 0 {
|
||||||
|
fileTimeFormat = c.FileTimeFormat
|
||||||
|
}
|
||||||
|
|
||||||
atomic.StoreUint32(&maxContentLength, c.MaxContentLength)
|
atomic.StoreUint32(&maxContentLength, c.MaxContentLength)
|
||||||
|
|
||||||
switch c.Encoding {
|
switch c.Encoding {
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
dateFormat = "2006-01-02"
|
dateFormat = "2006-01-02"
|
||||||
fileTimeFormat = time.RFC3339
|
|
||||||
hoursPerDay = 24
|
hoursPerDay = 24
|
||||||
bufferSize = 100
|
bufferSize = 100
|
||||||
defaultDirMode = 0o755
|
defaultDirMode = 0o755
|
||||||
@ -28,8 +27,11 @@ const (
|
|||||||
megaBytes = 1 << 20
|
megaBytes = 1 << 20
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrLogFileClosed is an error that indicates the log file is already closed.
|
var (
|
||||||
var ErrLogFileClosed = errors.New("error: log file closed")
|
// ErrLogFileClosed is an error that indicates the log file is already closed.
|
||||||
|
ErrLogFileClosed = errors.New("error: log file closed")
|
||||||
|
fileTimeFormat = time.RFC3339
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// A RotateRule interface is used to define the log rotating rules.
|
// A RotateRule interface is used to define the log rotating rules.
|
||||||
|
Loading…
Reference in New Issue
Block a user