evalphobia / logrus_sentry

sentry hook for logrus
MIT License
194 stars 78 forks source link

Refactor New() function and use one config argument #51

Open evalphobia opened 7 years ago

evalphobia commented 7 years ago

There are many New... method to create *SentryHook. To scale configuration, add a config struct and use it in New() function.

For example below,

// something like this
type Config struct {
    Levels []logrus.Level
    StacktraceConfiguration

    DSN string
    Async bool
    Tags map[string]string
    Release string
    Environment string
    // etc...
}

func New(conf Config) (*SentryHook, error) {
    client, err := raven.NewWithTags(conf.DSN, conf.Tags)
    if err != nil {
        return nil, err
    }

    if conf.Release != "" {
        client.SetRelease(conf.Release)
    }
    if conf.Environment != "" {
        client.SetEnvironment(conf.Environment)
    }

    hook := &SentryHook{
        asynchronous: conf.Async,
    }
   // etc...
}