mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
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.
This commit is contained in:
parent
2808de1e30
commit
01e192edc9
1 changed files with 24 additions and 19 deletions
|
@ -45,15 +45,21 @@ func (ConsoleEncoder) CaddyModule() caddy.ModuleInfo {
|
||||||
|
|
||||||
// Provision sets up the encoder.
|
// Provision sets up the encoder.
|
||||||
func (ce *ConsoleEncoder) Provision(_ caddy.Context) error {
|
func (ce *ConsoleEncoder) Provision(_ caddy.Context) error {
|
||||||
|
if ce.LevelFormat == "" {
|
||||||
|
ce.LevelFormat = "color"
|
||||||
|
}
|
||||||
|
if ce.TimeFormat == "" {
|
||||||
|
ce.TimeFormat = "wall_milli"
|
||||||
|
}
|
||||||
ce.Encoder = zapcore.NewConsoleEncoder(ce.ZapcoreEncoderConfig())
|
ce.Encoder = zapcore.NewConsoleEncoder(ce.ZapcoreEncoderConfig())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// console {
|
// console {
|
||||||
// <common encoder config subdirectives...>
|
// <common encoder config subdirectives...>
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// See the godoc on the LogEncoderConfig type for the syntax of
|
// See the godoc on the LogEncoderConfig type for the syntax of
|
||||||
// subdirectives that are common to most/all encoders.
|
// subdirectives that are common to most/all encoders.
|
||||||
|
@ -92,9 +98,9 @@ func (je *JSONEncoder) Provision(_ caddy.Context) error {
|
||||||
|
|
||||||
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// json {
|
// json {
|
||||||
// <common encoder config subdirectives...>
|
// <common encoder config subdirectives...>
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// See the godoc on the LogEncoderConfig type for the syntax of
|
// See the godoc on the LogEncoderConfig type for the syntax of
|
||||||
// subdirectives that are common to most/all encoders.
|
// subdirectives that are common to most/all encoders.
|
||||||
|
@ -127,19 +133,18 @@ type LogEncoderConfig struct {
|
||||||
|
|
||||||
// UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:
|
// UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:
|
||||||
//
|
//
|
||||||
// {
|
// {
|
||||||
// message_key <key>
|
// message_key <key>
|
||||||
// level_key <key>
|
// level_key <key>
|
||||||
// time_key <key>
|
// time_key <key>
|
||||||
// name_key <key>
|
// name_key <key>
|
||||||
// caller_key <key>
|
// caller_key <key>
|
||||||
// stacktrace_key <key>
|
// stacktrace_key <key>
|
||||||
// line_ending <char>
|
// line_ending <char>
|
||||||
// time_format <format>
|
// time_format <format>
|
||||||
// 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()
|
||||||
|
|
Loading…
Reference in a new issue