Fixes from golangci-lint
This commit is contained in:
parent
e2ac0ad45e
commit
7c425e25cb
15
merr/merr.go
15
merr/merr.go
@ -13,22 +13,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/mediocregopher/mediocre-go-lib/v2/mctx"
|
"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
|
type annotateKey string
|
||||||
|
|
||||||
// Error wraps an error such that contextual and stacktrace information is
|
// Error wraps an error such that contextual and stacktrace information is
|
||||||
@ -62,7 +50,7 @@ func (e Error) FullError() string {
|
|||||||
sb.WriteString(": ")
|
sb.WriteString(": ")
|
||||||
|
|
||||||
// if there's no newlines then print v inline with k
|
// 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)
|
sb.WriteString(v)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -111,6 +99,7 @@ func Wrap(ctx context.Context, err error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is a shortcut for:
|
// New is a shortcut for:
|
||||||
|
//
|
||||||
// merr.WrapSkip(ctx, errors.New(str), 1)
|
// merr.WrapSkip(ctx, errors.New(str), 1)
|
||||||
func New(ctx context.Context, str string) error {
|
func New(ctx context.Context, str string) error {
|
||||||
return WrapSkip(ctx, errors.New(str), 1)
|
return WrapSkip(ctx, errors.New(str), 1)
|
||||||
|
@ -9,7 +9,7 @@ package mlog
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -23,7 +23,7 @@ type mlogAnnotation string
|
|||||||
|
|
||||||
// Null is an instance of Logger which will write all Messages to /dev/null.
|
// Null is an instance of Logger which will write all Messages to /dev/null.
|
||||||
var Null = NewLogger(&LoggerOpts{
|
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
|
// 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 {
|
if msg.Level.Int() < 0 {
|
||||||
l.opts.MessageHandler.Sync()
|
if err := l.opts.MessageHandler.Sync(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user