コード例 #1
0
ファイル: logger.go プロジェクト: StorageTW/minio
// log2Mongo enables logging to mongodb. Use capped collection to
func log2Mongo(url, db, collection string) *probe.Error {
	hooker, e := mgorus.NewHooker(url, db, collection)
	if e != nil {
		return probe.NewError(e)
	}

	log.Hooks.Add(hooker)                   // Add mongodb hook.
	log.Formatter = &logrus.JSONFormatter{} // JSON formatted log.
	log.Level = logrus.InfoLevel            // Minimum log level.
	return nil
}
コード例 #2
0
func init() {

	log.Formatter = new(logrus.JSONFormatter)
	log.Level = logrus.DebugLevel
	log.Out = os.Stderr
	hooker, err := mgorus.NewHooker(c.Conf.Mongo.Host, c.Conf.Mongo.Database, c.Conf.Mongo.LogCollection)
	if err == nil {
		log.Hooks.Add(hooker)
	}

	if len(c.Conf.Slack.HookUrl) != 0 {
		log.Hooks.Add(&slackrus.SlackrusHook{
			HookURL:        c.Conf.Slack.HookUrl,
			AcceptedLevels: slackrus.LevelThreshold(logrus.ErrorLevel),
			Channel:        c.Conf.Slack.Channel,
			Username:       c.Conf.Slack.Username,
		})
	}
}