Shook(Slack hook)
logrus hook for slack incoming webhook
Installation
go get -u github.com/seon1-kim/shook
How to use
hook := &shook.Hook{
HookURL: "https://hooks.slack.com/services/ABCD1234/EFGHI/AbCdEfg",
Channel: "#log",
AcceptedLevels: logrus.InfoLevel,
Colors: nil,
}
logger := logrus.New()
logger.AddHook(hook)
logger.Info("Hello")
or if you want set attachment color manually
(color format must be '#AAAAAA' or 'good, warning, danger(slack default color type)')
colors := map[string]string{
"panic:": "danger",
"fatal:": "danger",
"error": "warning",
"warn": "#FFE400",
"info": "good",
"debug": "#439FE0",
"trace": "#439FE0",
}
hook := &shook.Hook{
HookURL: "https://hooks.slack.com/services/ABCD1234/EFGHI/AbCdEfg",
Channel: "#log",
AcceptedLevels: logrus.InfoLevel,
Colors: colors,
}
Also, you can customize slack webhook's name and emoji.
hook := &shook.Hook{
HookURL: "https://hooks.slack.com/services/ABCD1234/EFGHI/AbCdEfg",
Channel: "#log",
AcceptedLevels: logrus.InfoLevel,
Colors: nil,
Username: "Slackhook",
IconEmoji: "exclamation",
}
Example
Reference
multiplay/go-slack
License
MIT licensed.