mirror of https://github.com/go-gorm/gorm.git
Document Logger
This commit is contained in:
parent
f2c7beb19f
commit
c097a1919c
23
README.md
23
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Loading…
Reference in New Issue