onrik/logrus

GORM add to support FieldLogger

Closed this issue · 1 comments

please change to use log.FieldLogger interface :

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

so that we can use either logrus.Logger or logrus.Entry
we can also use existing preconfigured logrus Logger with this change.

package main

import (
    "github.com/jinzhu/gorm"
    gormlog "github.com/onrik/logrus/gorm"
    "github.com/sirupsen/logrus"
)

func main() {
    db, err := gorm.Open("<driver>", "<dsn>")
    if err != nil {
        logrus.Fatal(err)
    }

    db.SetLogger(gormlog.New(logrus.WithFields(log.Fields{"app": "gorm"})))
    //db.SetLogger(gormlog.New(logrus.StandardLogger()))
    db.LogMode(true) // Will log only on logrus debug level
}
onrik commented

Fixed in v0.4.1