func NewSlackHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := SlackHookConfig{} if err = options.ToObject(&conf); err != nil { return } levels := []logrus.Level{} if conf.Levels != nil { for _, level := range conf.Levels { if lv, e := logrus.ParseLevel(level); e != nil { err = e return } else { levels = append(levels, lv) } } } if len(levels) == 0 && conf.Levels != nil { levels = append(levels, logrus.ErrorLevel, logrus.PanicLevel, logrus.FatalLevel) } hook = &slackrus.SlackrusHook{ HookURL: conf.URL, AcceptedLevels: levels, Channel: conf.Channel, IconEmoji: conf.Emoji, Username: conf.Username, } return }
func NewRedisIOWriter(options logrus_mate.Options) (writer io.Writer, err error) { conf := RedisIOConfig{} if err = options.ToObject(&conf); err != nil { return } if conf.ListName == "" { err = errors.New("logurs mate: redisio's list name is empty") return } if conf.Network == "" { conf.Network = "tcp" } if conf.Address == "" { conf.Address = "127.0.0.1:6379" } var redisCli *redis.Client redisOpt := &redis.Options{ Network: conf.Network, Addr: conf.Address, Password: conf.Password, DB: conf.Db, } redisCli = redis.NewClient(redisOpt) writer, err = redisio.NewWriter(redisCli, conf.ListName) return }
func NewSyslogHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := SyslogHookConfig{} if err = options.ToObject(&conf); err != nil { return } return logrus_syslog.NewSyslogHook( conf.Network, conf.Address, toPriority(conf.Priority), conf.Tag) }
func NewAirbrakeHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := AirbrakeHookConfig{} if err = options.ToObject(&conf); err != nil { return } hook = airbrake.NewHook( int64(conf.ProjectId), conf.APIKey, conf.Env) return }
func NewGraylogHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := GraylogHookConfig{} if err = options.ToObject(&conf); err != nil { return } hook = graylog.NewAsyncGraylogHook( conf.Address, conf.Extra) return }
func NewMailHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := MailHookConfig{} if err = options.ToObject(&conf); err != nil { return } hook, err = logrus_mail.NewMailAuthHook( conf.AppName, conf.Host, conf.Port, conf.From, conf.To, conf.Username, conf.Password) return }
func NewBugsnagHook(options logrus_mate.Options) (hook logrus.Hook, err error) { conf := BugsnagHookConfig{} if err = options.ToObject(&conf); err != nil { return } bugsnag.Configure(bugsnag.Configuration{ Endpoint: conf.Endpoint, ReleaseStage: conf.ReleaseStage, APIKey: conf.APIKey, Synchronous: conf.Synchronous, }) hook, err = logrus_bugsnag.NewBugsnagHook() return }