Skip to content

Commit

Permalink
minor refactor (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriyselivanov authored Feb 2, 2022
1 parent 6627f5d commit 92e8e38
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ func (z *Zaplog) PanicErr(e error) *Zaplog {
return z
}

func (z *Zaplog) WithCropIfNeeded(key string, value interface{}) *Zaplog {
// AnyCropped takes a key and an arbitrary value and chooses the best way to represent them as a field.
// It crops the content if it is larger than 200 characters.
func AnyCropped(key string, value interface{}) zap.Field {
valueJson, err := json.Marshal(value)
if err != nil {
return z
if err != nil || len(valueJson) <= MaxAttributeChars {
return zap.Any(key, value)
}

if len(valueJson) <= MaxAttributeChars {
return z.With(zap.Any(key, value))
}
return z.With(zap.ByteString(key, valueJson[0:MaxAttributeChars]))
return zap.ByteString(key, valueJson[0:MaxAttributeChars])
}

0 comments on commit 92e8e38

Please sign in to comment.