forked from mirror/gorm
Initalize default logger when initalize DB
This commit is contained in:
parent
ccae2f0345
commit
66bfcec72e
|
@ -16,8 +16,8 @@ type Logger struct {
|
|||
*log.Logger
|
||||
}
|
||||
|
||||
//var default_logger = log.New(os.Stdout, "\r\n", 0)
|
||||
var default_logger = Logger{log.New(os.Stdout, "\r\n", 0)}
|
||||
//var defaultLogger = log.New(os.Stdout, "\r\n", 0)
|
||||
var defaultLogger = Logger{log.New(os.Stdout, "\r\n", 0)}
|
||||
|
||||
func (logger Logger) Print(v ...interface{}) {
|
||||
if len(v) > 1 {
|
||||
|
|
1
main.go
1
main.go
|
@ -23,6 +23,7 @@ func Open(driver, source string) (db DB, err error) {
|
|||
db.db, err = sql.Open(driver, source)
|
||||
db.dialect = dialect.New(driver)
|
||||
db.tagIdentifier = "sql"
|
||||
db.logger = defaultLogger
|
||||
db.parent = &db
|
||||
return
|
||||
}
|
||||
|
|
|
@ -72,12 +72,7 @@ func (s *DB) hasError() bool {
|
|||
|
||||
func (s *DB) print(level string, v ...interface{}) {
|
||||
if s.logMode == 2 || level == "debug" {
|
||||
if _, ok := s.parent.logger.(logger); !ok {
|
||||
fmt.Println("logger haven't been set, using os.Stdout")
|
||||
s.parent.logger = default_logger
|
||||
}
|
||||
args := []interface{}{level}
|
||||
s.parent.logger.(logger).Print(append(args, v...)...)
|
||||
s.parent.logger.(logger).Print(append([]interface{}{level}, v...)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue