mirror of https://github.com/go-gorm/gorm.git
Use log.PrintX instead of fmt.PrintX (#1634)
This commit is contained in:
parent
3a9e91ab37
commit
9c9de89686
12
callback.go
12
callback.go
|
@ -1,8 +1,6 @@
|
||||||
package gorm
|
package gorm
|
||||||
|
|
||||||
import (
|
import "log"
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultCallback default callbacks defined by gorm
|
// DefaultCallback default callbacks defined by gorm
|
||||||
var DefaultCallback = &Callback{}
|
var DefaultCallback = &Callback{}
|
||||||
|
@ -95,7 +93,7 @@ func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor {
|
||||||
func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) {
|
func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) {
|
||||||
if cp.kind == "row_query" {
|
if cp.kind == "row_query" {
|
||||||
if cp.before == "" && cp.after == "" && callbackName != "gorm:row_query" {
|
if cp.before == "" && cp.after == "" && callbackName != "gorm:row_query" {
|
||||||
fmt.Printf("Registing RowQuery callback %v without specify order with Before(), After(), applying Before('gorm:row_query') by default for compatibility...\n", callbackName)
|
log.Printf("Registing RowQuery callback %v without specify order with Before(), After(), applying Before('gorm:row_query') by default for compatibility...\n", callbackName)
|
||||||
cp.before = "gorm:row_query"
|
cp.before = "gorm:row_query"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +107,7 @@ func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *
|
||||||
// Remove a registered callback
|
// Remove a registered callback
|
||||||
// db.Callback().Create().Remove("gorm:update_time_stamp_when_create")
|
// db.Callback().Create().Remove("gorm:update_time_stamp_when_create")
|
||||||
func (cp *CallbackProcessor) Remove(callbackName string) {
|
func (cp *CallbackProcessor) Remove(callbackName string) {
|
||||||
fmt.Printf("[info] removing callback `%v` from %v\n", callbackName, fileWithLineNum())
|
log.Printf("[info] removing callback `%v` from %v\n", callbackName, fileWithLineNum())
|
||||||
cp.name = callbackName
|
cp.name = callbackName
|
||||||
cp.remove = true
|
cp.remove = true
|
||||||
cp.parent.processors = append(cp.parent.processors, cp)
|
cp.parent.processors = append(cp.parent.processors, cp)
|
||||||
|
@ -122,7 +120,7 @@ func (cp *CallbackProcessor) Remove(callbackName string) {
|
||||||
// scope.SetColumn("Updated", now)
|
// scope.SetColumn("Updated", now)
|
||||||
// })
|
// })
|
||||||
func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *Scope)) {
|
func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *Scope)) {
|
||||||
fmt.Printf("[info] replacing callback `%v` from %v\n", callbackName, fileWithLineNum())
|
log.Printf("[info] replacing callback `%v` from %v\n", callbackName, fileWithLineNum())
|
||||||
cp.name = callbackName
|
cp.name = callbackName
|
||||||
cp.processor = &callback
|
cp.processor = &callback
|
||||||
cp.replace = true
|
cp.replace = true
|
||||||
|
@ -161,7 +159,7 @@ func sortProcessors(cps []*CallbackProcessor) []*func(scope *Scope) {
|
||||||
for _, cp := range cps {
|
for _, cp := range cps {
|
||||||
// show warning message the callback name already exists
|
// show warning message the callback name already exists
|
||||||
if index := getRIndex(allNames, cp.name); index > -1 && !cp.replace && !cp.remove {
|
if index := getRIndex(allNames, cp.name); index > -1 && !cp.replace && !cp.remove {
|
||||||
fmt.Printf("[warning] duplicated callback `%v` from %v\n", cp.name, fileWithLineNum())
|
log.Printf("[warning] duplicated callback `%v` from %v\n", cp.name, fileWithLineNum())
|
||||||
}
|
}
|
||||||
allNames = append(allNames, cp.name)
|
allNames = append(allNames, cp.name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue