Skip to content

Commit

Permalink
Rename DisableVerbose to DisableErrorVerbose
Browse files Browse the repository at this point in the history
  • Loading branch information
makotonakai committed Feb 2, 2025
1 parent ac6d75b commit d3399cc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ type Config struct {
ErrorOutputPaths []string `json:"errorOutputPaths" yaml:"errorOutputPaths"`
// InitialFields is a collection of fields to add to the root logger.
InitialFields map[string]interface{} `json:"initialFields" yaml:"initialFields"`
// DisableVerbose stops printing error verbose in the error log.
DisableVerbose bool `json:"disableVerbose" yaml:"disableVerbose"`
// DisableErrorVerbose stops printing error verbose in the error log.
DisableErrorVerbose bool `json:"disableErrorVerbose" yaml:"disableErrorVerbose"`
}

// NewProductionEncoderConfig returns an opinionated EncoderConfig for
Expand Down Expand Up @@ -168,7 +168,7 @@ func NewProductionConfig() Config {
EncoderConfig: NewProductionEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
DisableVerbose: true,
DisableErrorVerbose: true,
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ func NewDevelopmentConfig() Config {
EncoderConfig: NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
DisableVerbose: true,
DisableErrorVerbose: true,
}
}

Expand Down Expand Up @@ -285,8 +285,8 @@ func (cfg Config) buildOptions(errSink zapcore.WriteSyncer) []Option {
opts = append(opts, AddStacktrace(stackLevel))
}

if cfg.DisableVerbose {
opts = append(opts, DisableVerbose())
if cfg.DisableErrorVerbose {
opts = append(opts, DisableErrorVerbose())
}

if scfg := cfg.Sampling; scfg != nil {
Expand Down
4 changes: 2 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Logger struct {

clock zapcore.Clock

DisableVerbose bool
DisableErrorVerbose bool
}

// New constructs a new Logger from the provided zapcore.Core and Options. If
Expand Down Expand Up @@ -263,7 +263,7 @@ func (log *Logger) Warn(msg string, fields ...Field) {
func (log *Logger) Error(msg string, fields ...Field) {
if ce := log.check(ErrorLevel, msg); ce != nil {
for i := range fields {
fields[i].DisableVerbose = log.DisableVerbose
fields[i].DisableErrorVerbose = log.DisableErrorVerbose
}
ce.Write(fields...)
}
Expand Down
16 changes: 8 additions & 8 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ func WithClock(clock zapcore.Clock) Option {
})
}

// WithDisableVerbose configures the Logger to turn off the error verbose or not,
// depending on the value of disableVerbose. This is a generalized form of DisableVerbose.
func WithDisableVerbose(disableVerbose bool) Option {
// WithDisableErrorVerbose configures the Logger to turn off the error verbose or not,
// depending on the value of disableErrorVerbose. This is a generalized form of DisableErrorVerbose.
func WithDisableErrorVerbose(disableErrorVerbose bool) Option {
return optionFunc(func(log *Logger) {
log.DisableVerbose = disableVerbose
log.DisableErrorVerbose = disableErrorVerbose
})
}

// DisableVerbose configures the Logger to turn off the error verbose.
// See also WithDisableVerbose.
func DisableVerbose() Option {
return WithDisableVerbose(true)
// DisableErrorVerbose configures the Logger to turn off the error verbose.
// See also WithDisableErrorVerbose.
func DisableErrorVerbose() Option {
return WithDisableErrorVerbose(true)
}
6 changes: 3 additions & 3 deletions zapcore/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func encodeError(key string, err error, enc ObjectEncoder, opts ...bool) (retErr
case errorGroup:
return enc.AddArray(key+"Causes", errArray(e.Errors()))
case fmt.Formatter:
disableVerbose := false
disableErrorVerbose := false
if len(opts) > 0 {
disableVerbose = opts[0]
disableErrorVerbose = opts[0]
}
verbose := fmt.Sprintf("%+v", e)
if !disableVerbose && verbose != basic {
if !disableErrorVerbose && verbose != basic {
// This is a rich error type, like those produced by
// github.com/pkg/errors.
enc.AddString(key+"Verbose", verbose)
Expand Down
18 changes: 9 additions & 9 deletions zapcore/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,29 @@ func TestErrorEncoding(t *testing.T) {
tests := []struct {
key string
iface any
disableVerbose bool
disableErrorVerbose bool
want map[string]any
}{
{
key: "k",
iface: errTooManyUsers(2),
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"k": "2 too many users",
},
},
{
key: "k",
iface: errTooFewUsers(2),
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"k": "2 too few users",
},
},
{
key: "k",
iface: errTooFewUsers(2),
disableVerbose: false,
disableErrorVerbose: false,
want: map[string]any{
"k": "2 too few users",
"kVerbose": "verbose: 2 too few users",
Expand All @@ -116,7 +116,7 @@ func TestErrorEncoding(t *testing.T) {
errors.New("bar"),
errors.New("baz"),
),
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"err": "foo; bar; baz",
"errCauses": []any{
Expand All @@ -129,7 +129,7 @@ func TestErrorEncoding(t *testing.T) {
{
key: "e",
iface: customMultierr{},
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"e": "great sadness",
"eCauses": []any{
Expand All @@ -147,7 +147,7 @@ func TestErrorEncoding(t *testing.T) {
{
key: "k",
iface: fmt.Errorf("failed: %w", errors.New("egad")),
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"k": "failed: egad",
},
Expand All @@ -161,7 +161,7 @@ func TestErrorEncoding(t *testing.T) {
errors.New("baz"),
fmt.Errorf("world: %w", errors.New("qux")),
),
disableVerbose: true,
disableErrorVerbose: true,
want: map[string]any{
"error": "hello: foo; bar; baz; world: qux",
"errorCauses": []any{
Expand All @@ -177,7 +177,7 @@ func TestErrorEncoding(t *testing.T) {

for _, tt := range tests {
enc := NewMapObjectEncoder()
f := Field{Key: tt.key, Type: ErrorType, Interface: tt.iface, DisableVerbose: tt.disableVerbose}
f := Field{Key: tt.key, Type: ErrorType, Interface: tt.iface, DisableErrorVerbose: tt.disableErrorVerbose}
f.AddTo(enc)
assert.Equal(t, tt.want, enc.Fields, "Unexpected output from field %+v.", f)
}
Expand Down
4 changes: 2 additions & 2 deletions zapcore/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type Field struct {
Integer int64
String string
Interface interface{}
DisableVerbose bool
DisableErrorVerbose bool
}

// AddTo exports a field through the ObjectEncoder interface. It's primarily
Expand Down Expand Up @@ -174,7 +174,7 @@ func (f Field) AddTo(enc ObjectEncoder) {
case StringerType:
err = encodeStringer(f.Key, f.Interface, enc)
case ErrorType:
err = encodeError(f.Key, f.Interface.(error), enc, f.DisableVerbose)
err = encodeError(f.Key, f.Interface.(error), enc, f.DisableErrorVerbose)
case SkipType:
break
default:
Expand Down

0 comments on commit d3399cc

Please sign in to comment.