コード例 #1
0
ファイル: Run.go プロジェクト: spambarrier/anaLog
func Run() {
	defer func() {
		anaLog.Close()
		idl.Panic("shutdown")
	}()

	if config.AppLog.SlackLogUrl != "" {

		prio := priority.Warning
		if config.AnaLog.DevelopmentEnv {
			prio = priority.Debugging
		}

		idl.AddHook(&iDslackLog.SlackLogHook{
			AcceptedPriorities: priority.Threshold(prio),
			HookURL:            config.AppLog.SlackLogUrl,
			IconURL:            "",
			Channel:            "",
			IconEmoji:          "",
			Username:           "******",
		})
	}

	idl.StandardLogger().Async = true
	idl.SetPrefix("anaLog")
	idl.SetErrCallback(func(err error) {
		idl.StandardLogger().Async = true
		idl.Log(&idl.Event{
			idl.StandardLogger(),
			map[string]interface{}{
				"error": err,
			},
			time.Now(),
			priority.Emergency,
			"AppLogger caught an internal error",
		})
		panic("AppLogger caught an internal error")
	})

	if config.AnaLog.DevelopmentEnv {
		go scheduler.StartIn(1 * time.Second)
	} else {
		go scheduler.StartIn(10 * time.Second)
	}

	server.Listen()
}
コード例 #2
0
ファイル: mongo.go プロジェクト: spambarrier/anaLog
func connect2mgo() {
	var err error
	mgoSession, err = mgo.Dial(config.Mongo.Host)

	if err == nil {
		mgoSession.SetMode(mgo.Monotonic, true)
		if config.Mongo.User != "" && config.Mongo.Pass != "" {
			err = mgoSession.Login(&mgo.Credential{
				Username: config.Mongo.User,
				Password: config.Mongo.Pass,
			})
		}
	}
	if err != nil {
		idl.Panic(err)
	}
}