summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMohammed Al Sahaf <[email protected]>2024-03-22 05:17:09 +0300
committerGitHub <[email protected]>2024-03-21 22:17:09 -0400
commit0c01547037925016921e6b73f232a5f8758a8c08 (patch)
tree3ab26b986eed3f73b57abca9bee15f1f5f7598e8
parente7336cc3bfcf60eb775c60509d521e92a5a3b6fe (diff)
downloadcaddy-0c01547037925016921e6b73f232a5f8758a8c08.tar.gz
caddy-0c01547037925016921e6b73f232a5f8758a8c08.zip
logging: support `ms` duration format and add docs (#6187)
-rw-r--r--modules/logging/encoders.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/modules/logging/encoders.go b/modules/logging/encoders.go
index 7399423bf..5c563114b 100644
--- a/modules/logging/encoders.go
+++ b/modules/logging/encoders.go
@@ -118,17 +118,26 @@ func (je *JSONEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// LogEncoderConfig holds configuration common to most encoders.
type LogEncoderConfig struct {
- MessageKey *string `json:"message_key,omitempty"`
- LevelKey *string `json:"level_key,omitempty"`
- TimeKey *string `json:"time_key,omitempty"`
- NameKey *string `json:"name_key,omitempty"`
- CallerKey *string `json:"caller_key,omitempty"`
- StacktraceKey *string `json:"stacktrace_key,omitempty"`
- LineEnding *string `json:"line_ending,omitempty"`
- TimeFormat string `json:"time_format,omitempty"`
- TimeLocal bool `json:"time_local,omitempty"`
- DurationFormat string `json:"duration_format,omitempty"`
- LevelFormat string `json:"level_format,omitempty"`
+ MessageKey *string `json:"message_key,omitempty"`
+ LevelKey *string `json:"level_key,omitempty"`
+ TimeKey *string `json:"time_key,omitempty"`
+ NameKey *string `json:"name_key,omitempty"`
+ CallerKey *string `json:"caller_key,omitempty"`
+ StacktraceKey *string `json:"stacktrace_key,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"`
+ 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"`
+
+ // Recognized values are: lower, upper, color.
+ // Empty and unrecognized value default to lower.
+ LevelFormat string `json:"level_format,omitempty"`
}
// UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:
@@ -260,12 +269,16 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
// duration format
var durFormatter zapcore.DurationEncoder
switch lec.DurationFormat {
- case "", "seconds":
+ case "s", "second", "seconds":
durFormatter = zapcore.SecondsDurationEncoder
- case "nano":
+ case "ns", "nano", "nanos":
durFormatter = zapcore.NanosDurationEncoder
+ case "ms", "milli", "millis":
+ durFormatter = zapcore.MillisDurationEncoder
case "string":
durFormatter = zapcore.StringDurationEncoder
+ default:
+ durFormatter = zapcore.SecondsDurationEncoder
}
cfg.EncodeDuration = durFormatter