Example #1
0
// Must initialize the mongo session
func InitMongo(url string) (err error) {
	mongolog := log.New(os.Stderr, "MONGO ", log.LstdFlags)
	mgo.SetLogger(mongolog)
	mgo.SetDebug(true)
	session, err = mgo.Dial(url)
	return err
}
Example #2
0
func (s *S) SetUpTest(c *C) {
	err := run("mongo --nodb testdb/dropall.js")
	if err != nil {
		panic(err.Error())
	}
	mgo.SetLogger((*cLogger)(c))
	mgo.ResetStats()
}
Example #3
0
func openMgoSession(t *testing.T) *mgo.Session {
	mgo.SetLogger(log.New(os.Stderr, "MONGO ", log.LstdFlags))
	mgo.SetDebug(true)
	s, err := mgo.Dial("localhost")
	if err != nil {
		t.Fatalf("Error opening mongo session. %v", err)
	}
	return s
}
// sets global logger based on verbosity level in configuration
// optional parameter:  default.verbose (defaults to true if not present or incorrectly set)
func InitLogger() {
	verbose, err := configFile.GetBool("default", "verbose")
	logger = log4go.NewVerboseLogger(verbose, nil, "")
	if err != nil {
		logger.Warn(err)
		verbose = true
	}
	logger.Printf("verbose set [%v]", verbose)

	if verbose {
		mgo.SetLogger(logger)
		mgo.SetDebug(verbose)
	}
}