Document Logger

This commit is contained in:
Jinzhu 2013-11-11 17:50:27 +08:00
parent f2c7beb19f
commit c097a1919c
3 changed files with 24 additions and 0 deletions

View File

@ -10,6 +10,7 @@ Yet Another ORM library for Go, aims for developer friendly
* Soft Delete * Soft Delete
* Auto Migration * Auto Migration
* Transaction * Transaction
* Logger Support
* Every feature comes with tests * Every feature comes with tests
* Convention Over Configuration * Convention Over Configuration
* Developer Friendly * Developer Friendly
@ -636,6 +637,28 @@ tx.Rollback()
tx.Commit() 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 ## Run Raw SQl
```go ```go

View File

@ -86,6 +86,7 @@ func init() {
// GRANT ALL ON gorm.* TO 'gorm'@'localhost'; // GRANT ALL ON gorm.* TO 'gorm'@'localhost';
// db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True") // db, err = Open("mysql", "gorm:gorm@/gorm?charset=utf8&parseTime=True")
// db, err = Open("sqlite3", "/tmp/gorm.db") // db, err = Open("sqlite3", "/tmp/gorm.db")
// db.SetLogger(log.New(os.Stdout, "\r\n", 0))
db.LogMode(true) db.LogMode(true)
if err != nil { if err != nil {

BIN
images/logger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB