@marcel91200 / caddy Mirror · read-only / commits / 01e192ed
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 13, 09:15 UTC

logging: Better `console` encoder defaults (#5109)

This is something that has bothered me for a while, so I figured I'd do something about it now since I'm playing in the logging code lately. The `console` encoder doesn't actually match the defaults that zap's default logger uses. This makes it match better with the rest of the logs when using the `console` encoder alongside somekind of filter, which requires you to configure an encoder to wrap.

Francis Lavoie committed Oct 4, 2022 at 23:18 UTC 01e192edc9e11ceb92dd02eb79efde087838831a
1 file changed +24 -19
modules/logging/encoders.go
+24 -19
@@ -45,15 +45,21 @@ func (ConsoleEncoder) CaddyModule() caddy.ModuleInfo {
45
46 // Provision sets up the encoder.
47 func (ce *ConsoleEncoder) Provision(_ caddy.Context) error {
48 + if ce.LevelFormat == "" {
49 + ce.LevelFormat = "color"
50 + }
51 + if ce.TimeFormat == "" {
52 + ce.TimeFormat = "wall_milli"
53 + }
54 ce.Encoder = zapcore.NewConsoleEncoder(ce.ZapcoreEncoderConfig())
55 return nil
56 }
57
58 // UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
59 //
54 -// console {
55 -// <common encoder config subdirectives...>
56 -// }
60 +// console {
61 +// <common encoder config subdirectives...>
62 +// }
63 //
64 // See the godoc on the LogEncoderConfig type for the syntax of
65 // subdirectives that are common to most/all encoders.
@@ -92,9 +98,9 @@ func (je *JSONEncoder) Provision(_ caddy.Context) error {
98
99 // UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
100 //
95 -// json {
96 -// <common encoder config subdirectives...>
97 -// }
101 +// json {
102 +// <common encoder config subdirectives...>
103 +// }
104 //
105 // See the godoc on the LogEncoderConfig type for the syntax of
106 // subdirectives that are common to most/all encoders.
@@ -127,19 +133,18 @@ type LogEncoderConfig struct {
133
134 // UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:
135 //
130 -// {
131 -// message_key <key>
132 -// level_key <key>
133 -// time_key <key>
134 -// name_key <key>
135 -// caller_key <key>
136 -// stacktrace_key <key>
137 -// line_ending <char>
138 -// time_format <format>
139 -// duration_format <format>
140 -// level_format <format>
141 -// }
142 -//
136 +// {
137 +// message_key <key>
138 +// level_key <key>
139 +// time_key <key>
140 +// name_key <key>
141 +// caller_key <key>
142 +// stacktrace_key <key>
143 +// line_ending <char>
144 +// time_format <format>
145 +// duration_format <format>
146 +// level_format <format>
147 +// }
148 func (lec *LogEncoderConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
149 for nesting := d.Nesting(); d.NextBlock(nesting); {
150 subdir := d.Val()