Created
September 5, 2015 16:10
-
-
Save bnadland/2e4287b801a47dcfcc94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
log "github.com/sirupsen/logrus" | |
"github.com/jinzhu/gorm" | |
) | |
type GormLogger struct {} | |
func (*GormLogger) Print(v ...interface{}) { | |
if v[0] == "sql" { | |
log.WithFields(log.Fields{"module": "gorm", "type": "sql"}).Print(v[3]) | |
} | |
if v[0] == "log" { | |
log.WithFields(log.Fields{"module": "gorm", "type": "log"}).Print(v[2]) | |
} | |
} | |
func main() { | |
db, _ := gorm.Open(...) | |
defer db.Close() | |
db.SetLogger(&GormLogger{}) | |
db.LogMode(true) | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!
Slight variation I made: