mirror of https://github.com/sirupsen/logrus.git
Remove dead panic in Entry.Panic
[Entry.log itself panics][0] when the log level is set to PanicLevel, (and
PanicLevel is always eneabled) so this second panic will never be reached.
[0]: 8ae478eb8a/entry.go (L253)
This commit is contained in:
parent
8ae478eb8a
commit
02fcb16005
1
entry.go
1
entry.go
|
@ -317,7 +317,6 @@ func (entry *Entry) Fatal(args ...interface{}) {
|
|||
|
||||
func (entry *Entry) Panic(args ...interface{}) {
|
||||
entry.Log(PanicLevel, args...)
|
||||
panic(fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Entry Printf family functions
|
||||
|
|
|
@ -167,6 +167,28 @@ func TestEntryPanicf(t *testing.T) {
|
|||
entry.WithField("err", errBoom).Panicf("kaboom %v", true)
|
||||
}
|
||||
|
||||
func TestEntryPanic(t *testing.T) {
|
||||
errBoom := fmt.Errorf("boom again")
|
||||
|
||||
defer func() {
|
||||
p := recover()
|
||||
assert.NotNil(t, p)
|
||||
|
||||
switch pVal := p.(type) {
|
||||
case *Entry:
|
||||
assert.Equal(t, "kaboom", pVal.Message)
|
||||
assert.Equal(t, errBoom, pVal.Data["err"])
|
||||
default:
|
||||
t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
|
||||
}
|
||||
}()
|
||||
|
||||
logger := New()
|
||||
logger.Out = &bytes.Buffer{}
|
||||
entry := NewEntry(logger)
|
||||
entry.WithField("err", errBoom).Panic("kaboom")
|
||||
}
|
||||
|
||||
const (
|
||||
badMessage = "this is going to panic"
|
||||
panicMessage = "this is broken"
|
||||
|
|
Loading…
Reference in New Issue