mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-24 08:49:01 +01:00
logging: Add time_local
option to use local time instead of UTC (#5108)
This commit is contained in:
parent
2be56c526c
commit
9e1d964bd6
1 changed files with 17 additions and 1 deletions
|
@ -127,6 +127,7 @@ type LogEncoderConfig struct {
|
||||||
StacktraceKey *string `json:"stacktrace_key,omitempty"`
|
StacktraceKey *string `json:"stacktrace_key,omitempty"`
|
||||||
LineEnding *string `json:"line_ending,omitempty"`
|
LineEnding *string `json:"line_ending,omitempty"`
|
||||||
TimeFormat string `json:"time_format,omitempty"`
|
TimeFormat string `json:"time_format,omitempty"`
|
||||||
|
TimeLocal bool `json:"time_local,omitempty"`
|
||||||
DurationFormat string `json:"duration_format,omitempty"`
|
DurationFormat string `json:"duration_format,omitempty"`
|
||||||
LevelFormat string `json:"level_format,omitempty"`
|
LevelFormat string `json:"level_format,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -142,12 +143,21 @@ type LogEncoderConfig struct {
|
||||||
// stacktrace_key <key>
|
// stacktrace_key <key>
|
||||||
// line_ending <char>
|
// line_ending <char>
|
||||||
// time_format <format>
|
// time_format <format>
|
||||||
|
// time_local
|
||||||
// duration_format <format>
|
// duration_format <format>
|
||||||
// level_format <format>
|
// level_format <format>
|
||||||
// }
|
// }
|
||||||
func (lec *LogEncoderConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
func (lec *LogEncoderConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
for nesting := d.Nesting(); d.NextBlock(nesting); {
|
for nesting := d.Nesting(); d.NextBlock(nesting); {
|
||||||
subdir := d.Val()
|
subdir := d.Val()
|
||||||
|
switch subdir {
|
||||||
|
case "time_local":
|
||||||
|
lec.TimeLocal = true
|
||||||
|
if d.NextArg() {
|
||||||
|
return d.ArgErr()
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
var arg string
|
var arg string
|
||||||
if !d.AllArgs(&arg) {
|
if !d.AllArgs(&arg) {
|
||||||
return d.ArgErr()
|
return d.ArgErr()
|
||||||
|
@ -237,7 +247,13 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
|
||||||
timeFormat = "02/Jan/2006:15:04:05 -0700"
|
timeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||||
}
|
}
|
||||||
timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
|
timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
|
||||||
encoder.AppendString(ts.UTC().Format(timeFormat))
|
var time time.Time
|
||||||
|
if lec.TimeLocal {
|
||||||
|
time = ts.Local()
|
||||||
|
} else {
|
||||||
|
time = ts.UTC()
|
||||||
|
}
|
||||||
|
encoder.AppendString(time.Format(timeFormat))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.EncodeTime = timeFormatter
|
cfg.EncodeTime = timeFormatter
|
||||||
|
|
Loading…
Reference in a new issue