📝📝 An Intuitive Logrus Hook for Slack
Using go get
$ go get -u github.com/codehakase/slack-logrus
Log Directly to A Slack Channel
package main
import (
"github.com/codehakase/slack-logrus"
"github.com/sirupsen/logrus"
)
func main() {
logrus.SetOutput(os.Stderr)
logrus.AddHook(&sl.Hook{
SlackHookURL: "https://hooks.slack.com/services/xxxxxx/xxxxxx/xxxxxxx",
Username: "slack-logrus",
IconEmoji: ":mega:",
WithLevels: logrus.AllLevels,
Channel: "#dev-channel",
})
logrus.Info("Hey I'm test running my package!!!")
}
To send custom fields to aid understand logging use add an Options
field
fields := map[string]interface{}{
"hostname": "hakaselabs",
"source": os.Getenv("APISource"),
"tag": "test-tag",
}
logrus.AddHook(&slacklogrus.Hook{
...
Options: fields,
})