2017-08-16 17:53:03 +05:30
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
2017-08-17 05:17:35 +05:30
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2017-08-16 17:53:03 +05:30
|
|
|
"os"
|
|
|
|
|
2017-09-04 01:15:38 +05:30
|
|
|
"github.com/assembla/cony"
|
2017-08-27 20:40:03 +05:30
|
|
|
"github.com/getsentry/raven-go"
|
2017-08-16 17:53:03 +05:30
|
|
|
"github.com/mono83/slf/rays"
|
|
|
|
"github.com/mono83/slf/recievers/ansi"
|
|
|
|
"github.com/mono83/slf/recievers/statsd"
|
|
|
|
"github.com/mono83/slf/wd"
|
2017-08-27 20:40:03 +05:30
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/logger/receivers/sentry"
|
2017-08-16 17:53:03 +05:30
|
|
|
)
|
|
|
|
|
2017-09-03 00:07:16 +05:30
|
|
|
var version = ""
|
|
|
|
|
|
|
|
func GetVersion() string {
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
2017-08-27 20:40:03 +05:30
|
|
|
func CreateLogger(statsdAddr string, sentryAddr string) (wd.Watchdog, error) {
|
2017-08-16 17:53:03 +05:30
|
|
|
wd.AddReceiver(ansi.New(true, true, false))
|
|
|
|
if statsdAddr != "" {
|
|
|
|
hostname, _ := os.Hostname()
|
|
|
|
statsdReceiver, err := statsd.NewReceiver(statsd.Config{
|
|
|
|
Address: statsdAddr,
|
|
|
|
Prefix: "ely.skinsystem." + hostname + ".app.",
|
|
|
|
FlushEvery: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
wd.AddReceiver(statsdReceiver)
|
|
|
|
}
|
|
|
|
|
2017-08-27 20:40:03 +05:30
|
|
|
if sentryAddr != "" {
|
|
|
|
ravenClient, err := raven.New(sentryAddr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ravenClient.SetEnvironment("production")
|
|
|
|
ravenClient.SetDefaultLoggerName("sentry-watchdog-receiver")
|
2017-09-03 00:07:16 +05:30
|
|
|
programVersion := GetVersion()
|
|
|
|
if programVersion != "" {
|
|
|
|
raven.SetRelease(programVersion)
|
|
|
|
}
|
2017-08-27 20:40:03 +05:30
|
|
|
|
|
|
|
sentryReceiver, err := sentry.NewReceiverWithCustomRaven(ravenClient, &sentry.Config{
|
|
|
|
MinLevel: "warn",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
wd.AddReceiver(sentryReceiver)
|
|
|
|
}
|
|
|
|
|
2017-08-16 17:53:03 +05:30
|
|
|
return wd.New("", "").WithParams(rays.Host), nil
|
|
|
|
}
|
2017-08-17 05:17:35 +05:30
|
|
|
|
|
|
|
type RabbitMQConfig struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
Host string
|
|
|
|
Port int
|
|
|
|
Vhost string
|
|
|
|
}
|
|
|
|
|
2017-09-04 01:15:38 +05:30
|
|
|
func CreateRabbitMQClient(config *RabbitMQConfig) *cony.Client {
|
2017-08-17 05:17:35 +05:30
|
|
|
addr := fmt.Sprintf(
|
|
|
|
"amqp://%s:%s@%s:%d/%s",
|
|
|
|
config.Username,
|
|
|
|
config.Password,
|
|
|
|
config.Host,
|
|
|
|
config.Port,
|
|
|
|
url.PathEscape(config.Vhost),
|
|
|
|
)
|
|
|
|
|
2017-09-04 01:15:38 +05:30
|
|
|
client := cony.NewClient(cony.URL(addr), cony.Backoff(cony.DefaultBackoff))
|
2017-08-17 05:17:35 +05:30
|
|
|
|
2017-09-04 01:15:38 +05:30
|
|
|
return client
|
2017-08-17 05:17:35 +05:30
|
|
|
}
|