From 66bfcec72e11dc5f41558e3d863a56a6f07b4117 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 4 Jan 2014 15:32:44 +0800 Subject: [PATCH] Initalize default logger when initalize DB --- logger.go | 4 ++-- main.go | 1 + private.go | 7 +------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/logger.go b/logger.go index 789bf088..f890d120 100644 --- a/logger.go +++ b/logger.go @@ -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 { diff --git a/main.go b/main.go index 8680aaee..538ae182 100644 --- a/main.go +++ b/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 } diff --git a/private.go b/private.go index b684a604..84235575 100644 --- a/private.go +++ b/private.go @@ -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...)...) } }