Beispiel #1
0
func (d *Db) setLoger() {
	if "prod" != beego.AppConfig.String("runmode") {
		mLog := log.New(os.Stderr, "", log.LstdFlags)
		mgo.SetLogger(mLog)
		mgo.SetDebug(true)
	}
}
Beispiel #2
0
func getDB(t *testing.T) *mgo.Database {
	session, err := mgo.Dial(os.Getenv("MONGODB_TEST_SERVER"))
	test.Fatal(t, err, nil)
	if verbose == true {
		mgo.SetLogger(MongoLogger{t})
		mgo.SetDebug(true)
	}
	return session.DB(os.Getenv("MONGODB_TEST_DB"))
}
Beispiel #3
0
func SetDB() (err error) {

	if DbCfg.LogMode == DB_LOG_MODE_DEBUG {
		logPath := path.Join(setting.LogRootPath, "mongo.log")
		os.MkdirAll(path.Dir(logPath), os.ModePerm)

		f, err := os.Create(logPath)
		if err != nil {
			return fmt.Errorf("models.init(fail to create xorm.log): %v", err)
		}
		mgo.SetLogger(log.New(f, "mongodb", log.Ltime))
		mgo.SetDebug(true)
	}

	return nil
}