mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 14:13:48 +03:00
logging: support ms
duration format and add docs (#6187)
This commit is contained in:
parent
e7336cc3bf
commit
0c01547037
1 changed files with 26 additions and 13 deletions
|
@ -125,9 +125,18 @@ type LogEncoderConfig struct {
|
||||||
CallerKey *string `json:"caller_key,omitempty"`
|
CallerKey *string `json:"caller_key,omitempty"`
|
||||||
StacktraceKey *string `json:"stacktrace_key,omitempty"`
|
StacktraceKey *string `json:"stacktrace_key,omitempty"`
|
||||||
LineEnding *string `json:"line_ending,omitempty"`
|
LineEnding *string `json:"line_ending,omitempty"`
|
||||||
|
|
||||||
|
// Recognized values are: unix_seconds_float, unix_milli_float, unix_nano, iso8601, rfc3339, rfc3339_nano, wall, wall_milli, wall_nano, common_log.
|
||||||
|
// The value may also be custom format per the Go `time` package layout specification, as described [here](https://pkg.go.dev/time#pkg-constants).
|
||||||
TimeFormat string `json:"time_format,omitempty"`
|
TimeFormat string `json:"time_format,omitempty"`
|
||||||
TimeLocal bool `json:"time_local,omitempty"`
|
TimeLocal bool `json:"time_local,omitempty"`
|
||||||
|
|
||||||
|
// Recognized values are: s/second/seconds, ns/nano/nanos, ms/milli/millis, string.
|
||||||
|
// Empty and unrecognized value default to seconds.
|
||||||
DurationFormat string `json:"duration_format,omitempty"`
|
DurationFormat string `json:"duration_format,omitempty"`
|
||||||
|
|
||||||
|
// Recognized values are: lower, upper, color.
|
||||||
|
// Empty and unrecognized value default to lower.
|
||||||
LevelFormat string `json:"level_format,omitempty"`
|
LevelFormat string `json:"level_format,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,12 +269,16 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
|
||||||
// duration format
|
// duration format
|
||||||
var durFormatter zapcore.DurationEncoder
|
var durFormatter zapcore.DurationEncoder
|
||||||
switch lec.DurationFormat {
|
switch lec.DurationFormat {
|
||||||
case "", "seconds":
|
case "s", "second", "seconds":
|
||||||
durFormatter = zapcore.SecondsDurationEncoder
|
durFormatter = zapcore.SecondsDurationEncoder
|
||||||
case "nano":
|
case "ns", "nano", "nanos":
|
||||||
durFormatter = zapcore.NanosDurationEncoder
|
durFormatter = zapcore.NanosDurationEncoder
|
||||||
|
case "ms", "milli", "millis":
|
||||||
|
durFormatter = zapcore.MillisDurationEncoder
|
||||||
case "string":
|
case "string":
|
||||||
durFormatter = zapcore.StringDurationEncoder
|
durFormatter = zapcore.StringDurationEncoder
|
||||||
|
default:
|
||||||
|
durFormatter = zapcore.SecondsDurationEncoder
|
||||||
}
|
}
|
||||||
cfg.EncodeDuration = durFormatter
|
cfg.EncodeDuration = durFormatter
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue