Slack hook for Logrus.
Fix import path
package main
import (
logrus "github.com/sirupsen/logrus"
"github.com/johntdyer/slackrus"
"os"
)
func main() {
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetOutput(os.Stderr)
logrus.SetLevel(logrus.DebugLevel)
logrus.AddHook(&slackrus.SlackrusHook{
HookURL: "https://hooks.slack.com/services/abc123/defghijklmnopqrstuvwxyz",
AcceptedLevels: slackrus.LevelThreshold(logrus.DebugLevel),
Channel: "#slack-testing",
IconEmoji: ":ghost:",
Username: "foobot",
})
logrus.Warn("warn")
logrus.Info("info")
logrus.Debug("debug")
}
You can also add some extra fields to be sent with every slack message
extra := map[string]interface{}{
"hostname": "nyc-server-1",
"tag": "some-tag",
}
logrus.AddHook(&slackrus.SlackrusHook{
//HookURL: "https://hooks.slack.com/services/abc123/defghijklmnopqrstuvwxyz",
Extra: extra,
})
- HookURL
- IconEmoji
- IconURL
- Username
- Channel
- Asynchronous
- Extra
go get github.com/johntdyer/slackrus
Based on hipchat handler by nuboLAB