Skip to content

Commit

Permalink
Use FieldLogger for gorm.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Aug 13, 2019
1 parent ebd9f98 commit 94ad747
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ var (
)

type Logger struct {
logrus *logrus.Logger
logrus logrus.FieldLogger
}

func New(l *logrus.Logger) *Logger {
func New(l logrus.FieldLogger) *Logger {
return &Logger{l}
}

func (l *Logger) Print(v ...interface{}) {
message, fields := Formatter(v...)
l.logrus.WithFields(fields).Debug(message)
l.logrus.Debug(Formatter(v...))
}

var Formatter = func(values ...interface{}) (message interface{}, fields logrus.Fields) {
var Formatter = func(values ...interface{}) (message interface{}) {
if len(values) < 1 {
return
}
fields = logrus.Fields{
"_source": formatSource(values[1].(string)),
}

if values[0] == "sql" {
formattedValues := []string{}
Expand Down Expand Up @@ -86,7 +82,7 @@ var Formatter = func(values ...interface{}) (message interface{}, fields logrus.
}
}

message = sql
message = sql + fmt.Sprintf(" [%s]", values[2])
} else {
message = values[2]
}
Expand Down

0 comments on commit 94ad747

Please sign in to comment.