Skip to content

Commit

Permalink
slack us the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lyoshenka committed Aug 15, 2018
1 parent 5f9db51 commit 74cb72f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 64 deletions.
69 changes: 43 additions & 26 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@
[[constraint]]
branch = "master"
name = "github.com/phayes/freeport"

[[constraint]]
branch = "master"
name = "github.com/johntdyer/slackrus"
2 changes: 2 additions & 0 deletions cmd/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"syscall"

"github.com/lbryio/reflector.go/db"
"github.com/lbryio/reflector.go/meta"
"github.com/lbryio/reflector.go/reflector"
"github.com/lbryio/reflector.go/store"

Expand All @@ -24,6 +25,7 @@ func init() {
}

func reflectorCmd(cmd *cobra.Command, args []string) {
log.Printf("reflector version %s", meta.Version)
db := new(db.SQL)
err := db.Connect(globalConfig.DBConn)
if err != nil {
Expand Down
83 changes: 50 additions & 33 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/lbryio/lbry.go/util"
"github.com/lbryio/reflector.go/dht"

"github.com/johntdyer/slackrus"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -20,6 +21,7 @@ type Config struct {
BucketRegion string `json:"bucket_region"`
BucketName string `json:"bucket_name"`
DBConn string `json:"db_conn"`
SlackHookURL string `json:"slack_hook_url"`
}

var verbose []string
Expand All @@ -34,39 +36,9 @@ var conf string
var globalConfig Config

var rootCmd = &cobra.Command{
Use: "prism",
Short: "Prism is a single entry point application with multiple sub modules which can be leveraged individually or together",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
debugLogger := logrus.New()
debugLogger.SetLevel(logrus.DebugLevel)

if util.InSlice(verboseAll, verbose) {
logrus.SetLevel(logrus.DebugLevel)
verbose = []string{verboseDHT, verboseNodeFinder}
}

for _, debugType := range verbose {
switch debugType {
case verboseDHT:
dht.UseLogger(debugLogger)
case verboseNodeFinder:
dht.NodeFinderUseLogger(debugLogger)
}
}

var err error
if conf == "" {
logrus.Errorln("--conf flag required")
os.Exit(1)
} else if conf != "none" {
globalConfig, err = loadConfig(conf)
if err != nil {
logrus.Error(err)
os.Exit(1)
}
}
},

Use: "prism",
Short: "Prism is a single entry point application with multiple sub modules which can be leveraged individually or together",
PersistentPreRun: preRun,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Expand All @@ -87,6 +59,51 @@ func Execute() {
}
}

func preRun(cmd *cobra.Command, args []string) {
debugLogger := logrus.New()
debugLogger.SetLevel(logrus.DebugLevel)
debugLogger.SetOutput(os.Stderr)

if util.InSlice(verboseAll, verbose) {
logrus.SetLevel(logrus.DebugLevel)
verbose = []string{verboseDHT, verboseNodeFinder}
}

for _, debugType := range verbose {
switch debugType {
case verboseDHT:
dht.UseLogger(debugLogger)
case verboseNodeFinder:
dht.NodeFinderUseLogger(debugLogger)
}
}

var err error
if conf == "" {
logrus.Errorln("--conf flag required")
os.Exit(1)
} else if conf != "none" {
globalConfig, err = loadConfig(conf)
if err != nil {
logrus.Error(err)
os.Exit(1)
}
}

if globalConfig.SlackHookURL != "" {
hook := &slackrus.SlackrusHook{
HookURL: globalConfig.SlackHookURL,
AcceptedLevels: slackrus.LevelThreshold(logrus.InfoLevel),
Channel: "#reflector-logs",
//IconEmoji: ":ghost:",
//Username: "reflector.go",
}
//logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.AddHook(hook)
debugLogger.AddHook(hook)
}
}

func checkErr(err error) {
if err != nil {
panic(err)
Expand Down

0 comments on commit 74cb72f

Please sign in to comment.