@marcel91200 / caddy Mirror · read-only / commits / 0c015470
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 14:30 UTC

logging: support `ms` duration format and add docs (#6187)

Mohammed Al Sahaf committed Mar 22, 2024 at 05:17 UTC 0c01547037925016921e6b73f232a5f8758a8c08
1 file changed +26 -13
modules/logging/encoders.go
+26 -13
@@ -118,17 +118,26 @@ func (je *JSONEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
118
119 // LogEncoderConfig holds configuration common to most encoders.
120 type LogEncoderConfig struct {
121 - MessageKey *string `json:"message_key,omitempty"`
122 - LevelKey *string `json:"level_key,omitempty"`
123 - TimeKey *string `json:"time_key,omitempty"`
124 - NameKey *string `json:"name_key,omitempty"`
125 - CallerKey *string `json:"caller_key,omitempty"`
126 - StacktraceKey *string `json:"stacktrace_key,omitempty"`
127 - LineEnding *string `json:"line_ending,omitempty"`
128 - TimeFormat string `json:"time_format,omitempty"`
129 - TimeLocal bool `json:"time_local,omitempty"`
130 - DurationFormat string `json:"duration_format,omitempty"`
131 - LevelFormat string `json:"level_format,omitempty"`
121 + MessageKey *string `json:"message_key,omitempty"`
122 + LevelKey *string `json:"level_key,omitempty"`
123 + TimeKey *string `json:"time_key,omitempty"`
124 + NameKey *string `json:"name_key,omitempty"`
125 + CallerKey *string `json:"caller_key,omitempty"`
126 + StacktraceKey *string `json:"stacktrace_key,omitempty"`
127 + LineEnding *string `json:"line_ending,omitempty"`
128 +
129 + // Recognized values are: unix_seconds_float, unix_milli_float, unix_nano, iso8601, rfc3339, rfc3339_nano, wall, wall_milli, wall_nano, common_log.
130 + // The value may also be custom format per the Go `time` package layout specification, as described [here](https://pkg.go.dev/time#pkg-constants).
131 + TimeFormat string `json:"time_format,omitempty"`
132 + TimeLocal bool `json:"time_local,omitempty"`
133 +
134 + // Recognized values are: s/second/seconds, ns/nano/nanos, ms/milli/millis, string.
135 + // Empty and unrecognized value default to seconds.
136 + DurationFormat string `json:"duration_format,omitempty"`
137 +
138 + // Recognized values are: lower, upper, color.
139 + // Empty and unrecognized value default to lower.
140 + LevelFormat string `json:"level_format,omitempty"`
141 }
142
143 // UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:
@@ -260,12 +269,16 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
269 // duration format
270 var durFormatter zapcore.DurationEncoder
271 switch lec.DurationFormat {
263 - case "", "seconds":
272 + case "s", "second", "seconds":
273 durFormatter = zapcore.SecondsDurationEncoder
265 - case "nano":
274 + case "ns", "nano", "nanos":
275 durFormatter = zapcore.NanosDurationEncoder
276 + case "ms", "milli", "millis":
277 + durFormatter = zapcore.MillisDurationEncoder
278 case "string":
279 durFormatter = zapcore.StringDurationEncoder
280 + default:
281 + durFormatter = zapcore.SecondsDurationEncoder
282 }
283 cfg.EncodeDuration = durFormatter
284