Skip to content

Commit

Permalink
adding _source
Browse files Browse the repository at this point in the history
implement : onrik#13
  • Loading branch information
xmlking authored Aug 13, 2019
1 parent 94ad747 commit d93e651
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ func New(l logrus.FieldLogger) *Logger {
}

func (l *Logger) Print(v ...interface{}) {
l.logrus.Debug(Formatter(v...))
message, fields := Formatter(v...)
if v[0] == "sql" {
l.logrus.WithFields(fields).WithFields(logrus.Fields{"type": "sql"}).Debug(message)
}
if v[0] == "log" {
l.logrus.WithFields(fields).WithFields(logrus.Fields{"type": "log"}).Debug(message)
}
}

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

if values[0] == "sql" {
formattedValues := []string{}
Expand Down

0 comments on commit d93e651

Please sign in to comment.