Skip to content

Commit

Permalink
Merge pull request #15 from ezr-ondrej/trace_level_panic
Browse files Browse the repository at this point in the history
Fixes a panic when Trace level log fired
  • Loading branch information
archdx authored Jan 11, 2024
2 parents a41ff05 + d425460 commit 262337b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func (w *Writer) Write(data []byte) (n int, err error) {
}

event, ok := w.parseLogEvent(data)
event.Level = levelsMapping[lvl]

if !ok {
return
}
event.Level, ok = levelsMapping[lvl]
if !ok {
return
}
Expand Down
23 changes: 23 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ func TestWrite(t *testing.T) {
require.True(t, beforeSendCalled)
}

func TestWrite_TraceDoesNotPanic(t *testing.T) {
beforeSendCalled := false
writer, err := New("", WithBeforeSend(func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
beforeSendCalled = true
return event
}))
require.Nil(t, err)

var zerologError error
zerolog.ErrorHandler = func(err error) {
zerologError = err
}

// use io.MultiWriter to enforce using the Write() method
log := zerolog.New(io.MultiWriter(writer)).With().Timestamp().
Str("requestId", "bee07485-2485-4f64-99e1-d10165884ca7").
Logger()
log.Trace().Msg("test message")

require.Nil(t, zerologError)
require.False(t, beforeSendCalled)
}

func TestWriteLevel(t *testing.T) {
beforeSendCalled := false
writer, err := New("", WithBeforeSend(func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
Expand Down

0 comments on commit 262337b

Please sign in to comment.