Skip to content

Commit

Permalink
logging: ⚠️ Deprecate logfmt encoder
Browse files Browse the repository at this point in the history
It is essentially broken because it occludes many log fields.

See: #3575
  • Loading branch information
mholt committed Jul 13, 2020
1 parent 2c71fb1 commit eda54c2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/logging/encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func (je *JSONEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {

// LogfmtEncoder encodes log entries as logfmt:
// https://www.brandur.org/logfmt
//
// Note that logfmt does not encode nested structures
// properly, so it is not a good fit for most logs.
//
// ⚠️ DEPRECATED. Do not use. It will eventually be removed
// from the standard Caddy modules. For more information,
// see https://github.com/caddyserver/caddy/issues/3575.
type LogfmtEncoder struct {
zapcore.Encoder `json:"-"`
LogEncoderConfig
Expand All @@ -133,7 +140,10 @@ func (LogfmtEncoder) CaddyModule() caddy.ModuleInfo {
}

// Provision sets up the encoder.
func (lfe *LogfmtEncoder) Provision(_ caddy.Context) error {
func (lfe *LogfmtEncoder) Provision(ctx caddy.Context) error {
ctx.Logger(lfe).Warn("the logfmt encoder is DEPRECATED and will soon be removed from the standard modules",
zap.String("recommendation", "switch to a log format that isn't broken"),
zap.String("more_info", "https://github.com/caddyserver/caddy/issues/3575"))
lfe.Encoder = zaplogfmt.NewEncoder(lfe.ZapcoreEncoderConfig())
return nil
}
Expand Down

0 comments on commit eda54c2

Please sign in to comment.