diff --git a/README.md b/README.md index d43f0549..68f782b5 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Yet Another ORM library for Go, aims for developer friendly * Soft Delete * Auto Migration * Transaction +* Logger Support * Every feature comes with tests * Convention Over Configuration * Developer Friendly @@ -636,6 +637,28 @@ tx.Rollback() tx.Commit() ``` +## Logger + +Grom has builtin logger support, enable it with: + +```go +db.LogMode(true) +``` + +![logger](https://github.com/jinzhu/gorm/raw/master/images/logger.png) + +```go +// Use your own logger +// Checkout gorm's default logger for how to format messages: https://github.com/jinzhu/gorm/blob/master/logger.go#files +db.SetLogger(log.New(os.Stdout, "\r\n", 0)) + +// Disable log +db.LogMode(false) + +// Enable log for a single operation, make debug easy +db.Debug().Where("name = ?", "jinzhu").First(&User{}) +``` + ## Run Raw SQl ```go diff --git a/gorm_test.go b/gorm_test.go index 25938301..8379a5b8 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -86,6 +86,7 @@ func init() { // GRANT ALL ON gorm.* TO 'gorm'@'localhost'; // db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True") // db, err = Open("sqlite3", "/tmp/gorm.db") + // db.SetLogger(log.New(os.Stdout, "\r\n", 0)) db.LogMode(true) if err != nil { diff --git a/images/logger.png b/images/logger.png new file mode 100644 index 00000000..d3151940 Binary files /dev/null and b/images/logger.png differ