Skip to content

Commit

Permalink
Shorten name of suffixKeyvals to introduce valuer
Browse files Browse the repository at this point in the history
or else with the valuer, names get too long.
  • Loading branch information
Vinay P committed Jun 24, 2020
1 parent c77db4c commit 136f894
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func With(logger Logger, keyvals ...interface{}) Logger {
// backing array is created if the slice must grow in Log or With.
// Using the extra capacity without copying risks a data race that
// would violate the Logger interface contract.
keyvals: kvs[:len(kvs):len(kvs)],
suffixKeyvals: l.suffixKeyvals,
hasValuer: l.hasValuer || containsValuer(keyvals),
keyvals: kvs[:len(kvs):len(kvs)],
sKeyvals: l.sKeyvals,
hasValuer: l.hasValuer || containsValuer(keyvals),
}
}

Expand Down Expand Up @@ -68,10 +68,10 @@ func WithPrefix(logger Logger, keyvals ...interface{}) Logger {
}
kvs = append(kvs, l.keyvals...)
return &context{
logger: l.logger,
keyvals: kvs,
suffixKeyvals: l.suffixKeyvals,
hasValuer: l.hasValuer || containsValuer(keyvals),
logger: l.logger,
keyvals: kvs,
sKeyvals: l.sKeyvals,
hasValuer: l.hasValuer || containsValuer(keyvals),
}
}

Expand All @@ -90,7 +90,7 @@ func WithSuffix(logger Logger, keyvals ...interface{}) Logger {
// backing array is created if the slice must grow in Log or With.
// Using the extra capacity without copying risks a data race that
// would violate the Logger interface contract.
n := len(l.suffixKeyvals) + len(keyvals)
n := len(l.sKeyvals) + len(keyvals)
if len(keyvals)%2 != 0 {
n++
}
Expand All @@ -99,12 +99,12 @@ func WithSuffix(logger Logger, keyvals ...interface{}) Logger {
if len(kvs)%2 != 0 {
kvs = append(kvs, ErrMissingValue)
}
kvs = append(l.suffixKeyvals, kvs...)
kvs = append(l.sKeyvals, kvs...)
return &context{
logger: l.logger,
keyvals: l.keyvals,
suffixKeyvals: kvs,
hasValuer: l.hasValuer || containsValuer(keyvals),
logger: l.logger,
keyvals: l.keyvals,
sKeyvals: kvs,
hasValuer: l.hasValuer || containsValuer(keyvals),
}
}

Expand All @@ -128,9 +128,9 @@ func WithSuffix(logger Logger, keyvals ...interface{}) Logger {
// returning a newly constructed context with a merged keyvals rather
// than simply wrapping the existing context.
type context struct {
logger Logger
keyvals []interface{}
suffixKeyvals []interface{}
logger Logger
keyvals []interface{}
sKeyvals []interface{}
hasValuer bool
}

Expand All @@ -149,16 +149,16 @@ func (l *context) Log(keyvals ...interface{}) error {
if len(kvs)%2 != 0 {
kvs = append(kvs, ErrMissingValue)
}
kvs = append(kvs, l.suffixKeyvals...)
kvs = append(kvs, l.sKeyvals...)
if l.hasValuer {
// If no keyvals were appended above then we must copy l.keyvals
// and l.suffixKeyvals so that future log events will reevaluate
// and l.sKeyvals so that future log events will reevaluate
// the stored Valuers.
if len(keyvals) == 0 {
kvs = append([]interface{}{}, append(l.keyvals, l.suffixKeyvals...)...)
kvs = append([]interface{}{}, append(l.keyvals, l.sKeyvals...)...)
}
bindValues(kvs[:(len(l.keyvals))])
bindValues(kvs[len(kvs) - len(l.suffixKeyvals):])
bindValues(kvs[len(kvs) - len(l.sKeyvals):])
}
return l.logger.Log(kvs...)
}
Expand Down

0 comments on commit 136f894

Please sign in to comment.