chrly/internal/di/logger.go
2024-03-13 01:29:26 +01:00

34 lines
647 B
Go

package di
import (
"github.com/defval/di"
"github.com/getsentry/raven-go"
"github.com/spf13/viper"
"ely.by/chrly/internal/version"
)
var loggerDiOptions = di.Options(
di.Provide(newSentry),
)
func newSentry(config *viper.Viper) (*raven.Client, error) {
sentryAddr := config.GetString("sentry.dsn")
if sentryAddr == "" {
return nil, nil
}
ravenClient, err := raven.New(sentryAddr)
if err != nil {
return nil, err
}
ravenClient.SetEnvironment("production")
ravenClient.SetDefaultLoggerName("sentry-watchdog-receiver")
ravenClient.SetRelease(version.Version())
raven.DefaultClient = ravenClient
return ravenClient, nil
}