From d93e651ec16ac717aafa40c59b92a1854cb22554 Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Tue, 13 Aug 2019 11:08:35 -0700 Subject: [PATCH] adding _source implement : https://github.com/onrik/logrus/issues/13 --- gorm/gorm.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gorm/gorm.go b/gorm/gorm.go index ebdbeb7..21b1693 100644 --- a/gorm/gorm.go +++ b/gorm/gorm.go @@ -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{}