diff --git a/merr/merr.go b/merr/merr.go index f109a39..629f1d8 100644 --- a/merr/merr.go +++ b/merr/merr.go @@ -13,22 +13,10 @@ import ( "context" "errors" "strings" - "sync" "github.com/mediocregopher/mediocre-go-lib/v2/mctx" ) -var strBuilderPool = sync.Pool{ - New: func() interface{} { return new(strings.Builder) }, -} - -func putStrBuilder(sb *strings.Builder) { - sb.Reset() - strBuilderPool.Put(sb) -} - -//////////////////////////////////////////////////////////////////////////////// - type annotateKey string // Error wraps an error such that contextual and stacktrace information is @@ -62,7 +50,7 @@ func (e Error) FullError() string { sb.WriteString(": ") // if there's no newlines then print v inline with k - if strings.Index(v, "\n") < 0 { + if strings.Contains(v, "\n") { sb.WriteString(v) continue } @@ -111,6 +99,7 @@ func Wrap(ctx context.Context, err error) error { } // New is a shortcut for: +// // merr.WrapSkip(ctx, errors.New(str), 1) func New(ctx context.Context, str string) error { return WrapSkip(ctx, errors.New(str), 1) diff --git a/mlog/mlog.go b/mlog/mlog.go index a6b358b..bd1e26e 100644 --- a/mlog/mlog.go +++ b/mlog/mlog.go @@ -9,7 +9,7 @@ package mlog import ( "context" "errors" - "io/ioutil" + "io" "os" "strings" "sync" @@ -23,7 +23,7 @@ type mlogAnnotation string // Null is an instance of Logger which will write all Messages to /dev/null. var Null = NewLogger(&LoggerOpts{ - MessageHandler: NewMessageHandler(ioutil.Discard), + MessageHandler: NewMessageHandler(io.Discard), }) // Truncate is a helper function to truncate a string to a given size. It will @@ -239,7 +239,9 @@ func (l *Logger) Log(msg Message) { } if msg.Level.Int() < 0 { - l.opts.MessageHandler.Sync() + if err := l.opts.MessageHandler.Sync(); err != nil { + panic(err) + } os.Exit(1) } }