Skip to content

Question: Ignoring certain calls to log #1116

Answered by abhinav
DuratarskeyK asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, yes this is possible,
but you'll have to either write a custom Zap core,
or customize the existing core with the WrapCore option.

Your Core will have to track fields added with Core.With,
probably returning a no-op core if one of the fields is the one you want to reject,
and then in Core.Write, inspect the provided fields,
and skip writing to the wrapped core if the fields meet your criteria.

Roughly something like:

type omitCore struct {
  zapcore.Core  // wrapped core
}

func (c *omitCore) With(fields []zapcore.Field) zapcore.Core {
  // If one of these fields is the one you want to skip messages for,
  // return a no-op core so that `logger.With(badField)` does not
  // try to s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by abhinav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1021 on June 15, 2022 12:50.