Skip to content

Commit

Permalink
Merge pull request #348 from hj24/master
Browse files Browse the repository at this point in the history
fix: 修复 sentryext custom_logger 会覆盖原有 error 类型的 bug
  • Loading branch information
fenngwd authored Sep 26, 2021
2 parents 25cd406 + 821f057 commit 96d7086
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions extensions/sentryext/custom_logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package custom_logger

import (
"errors"
"fmt"
"log"
"os"

Expand All @@ -26,42 +24,50 @@ func NewSentryErrorLogger() *sentryErrorLogger {
}
}

func (s *sentryErrorLogger) captureOriginException(v ...interface{}) {
for _, vv := range v {
if err, ok := vv.(error); ok {
sentry.CaptureException(err)
}
}
}

func (s *sentryErrorLogger) Print(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprint(v...)))
s.captureOriginException(v...)
s.Logger.Print(v...)
}

func (s *sentryErrorLogger) Printf(format string, v ...interface{}) {
sentry.CaptureException(fmt.Errorf(format, v...))
s.captureOriginException(v...)
s.Logger.Printf(format, v...)
}
func (s *sentryErrorLogger) Println(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprintln(v...)))
s.captureOriginException(v...)
s.Logger.Println(v...)
}

func (s *sentryErrorLogger) Fatal(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprint(v...)))
s.captureOriginException(v...)
s.Logger.Fatal(v...)
}
func (s *sentryErrorLogger) Fatalf(format string, v ...interface{}) {
sentry.CaptureException(fmt.Errorf(format, v...))
s.captureOriginException(v...)
s.Logger.Fatalf(format, v...)
}
func (s *sentryErrorLogger) Fatalln(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprintln(v...)))
s.captureOriginException(v...)
s.Logger.Fatalln(v...)
}

func (s *sentryErrorLogger) Panic(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprint(v...)))
s.captureOriginException(v...)
s.Logger.Panic(v...)
}
func (s *sentryErrorLogger) Panicf(format string, v ...interface{}) {
sentry.CaptureException(fmt.Errorf(format, v...))
s.captureOriginException(v...)
s.Logger.Panicf(format, v...)
}
func (s *sentryErrorLogger) Panicln(v ...interface{}) {
sentry.CaptureException(errors.New(fmt.Sprintln(v...)))
s.captureOriginException(v...)
s.Logger.Panicln(v...)
}

0 comments on commit 96d7086

Please sign in to comment.