Skip to content

Commit

Permalink
Merge pull request #16 from ezr-ondrej/breadcrumbs_with_level
Browse files Browse the repository at this point in the history
Add breadcrumbs support for WriteLevel
  • Loading branch information
archdx authored Jan 11, 2024
2 parents 262337b + 518c55f commit a5e7c6e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,26 @@ func (w *Writer) Write(data []byte) (n int, err error) {
// implements zerolog.LevelWriter
func (w *Writer) WriteLevel(level zerolog.Level, p []byte) (n int, err error) {
n = len(p)
if _, enabled := w.levels[level]; !enabled {

event, ok := w.parseLogEvent(p)
if !ok {
return
}
event.Level, ok = levelsMapping[level]
if !ok {
return
}

event, ok := w.parseLogEvent(p)
event.Level = levelsMapping[level]
if _, enabled := w.levels[level]; !enabled {
// if the level is not enabled, add event as a breadcrumb
w.addBreadcrumb(event)
return
}

if ok {
w.hub.CaptureEvent(event)
// should flush before os.Exit
if event.Level == sentry.LevelFatal {
w.hub.Flush(w.flushTimeout)
}
w.hub.CaptureEvent(event)
// should flush before os.Exit
if event.Level == sentry.LevelFatal {
w.hub.Flush(w.flushTimeout)
}
return
}
Expand Down

0 comments on commit a5e7c6e

Please sign in to comment.