Skip to content

Add option to wrap/override sink and encoder #1438

Open
@dkropachev

Description

Is your feature request related to a problem? Please describe.
I would want to override encoder, to mask some data out from logs, or encode it:

type MaskingEncoder struct {
	zapcore.Encoder
}

func (m *MaskingEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) {
	filtered := make([]zapcore.Field, 0, len(fields))
	for _, field := range fields {
		key := strings.ToLower(field.Key)
		if slices.ContainsFunc(skipFieldRegexps, func(r *regexp.Regexp) bool {
			return r.Match([]byte(key))
		}) {
			continue
		}
		filtered = append(filtered, field)
	}
	return m.Encoder.EncodeEntry(entry, filtered)
}

And I want to wrap sinker to dump all the requests to a buffer to test logging.

Describe the solution you'd like
I would like to do it same way it is done for zapcore.Core, via zap.WrapCore:

	l, err := zapConf.Build(zapcore.WrapEncoder())

Describe alternatives you've considered
Alternatives to wrap encoder:

  1. Wrap whole logger and filter out fields
  2. Register another encoder and fix all the configs to use it.
  3. Copy zapcore.Config.Build code and inject it in there

Alternatives to wrap sinker:

  1. Copy zapcore.Config.Build code and inject it in there

Is this a breaking change?
Nope

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions