Documentation
¶
Overview ¶
Slack Hooks for Logrus
package main
import (
"github.com/bluele/logrus_slack"
"github.com/sirupsen/logrus"
)
const (
// slack webhook url
hookURL = "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX"
)
func main() {
logrus.SetLevel(logrus.DebugLevel)
logrus.AddHook(&logrus_slack.SlackHook{
HookURL: hookURL,
AcceptedLevels: logrus_slack.LevelThreshold(logrus.WarnLevel),
Channel: "#general",
IconEmoji: ":ghost:",
Username: "logrus_slack",
})
logrus.WithFields(logrus.Fields{"foo": "bar", "foo2": "bar2"}).Warn("this is a warn level message")
logrus.Debug("this is a debug level message")
logrus.Info("this is an info level message")
logrus.Error("this is an error level message")
}
You can specify hook options via `SlackHook` attributes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AllLevels = []logrus.Level{ logrus.DebugLevel, logrus.InfoLevel, logrus.WarnLevel, logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel, }
Supported log levels
View Source
var LevelColorMap = map[logrus.Level]string{ logrus.DebugLevel: "#9B30FF", logrus.InfoLevel: "good", logrus.WarnLevel: "warning", logrus.ErrorLevel: "danger", logrus.FatalLevel: "danger", logrus.PanicLevel: "danger", }
View Source
var TimeoutError = errors.New("Request timed out")
Functions ¶
Types ¶
type SlackHook ¶
type SlackHook struct {
// Messages with a log level not contained in this array
// will not be dispatched. If nil, all messages will be dispatched.
AcceptedLevels []logrus.Level
HookURL string // Webhook URL
// slack post parameters
Username string // display name
Channel string // `#channel-name`
IconEmoji string // emoji string ex) ":ghost:":
IconURL string // icon url
FieldHeader string // a header above field data
Timeout time.Duration // request timeout
Async bool // if async is true, send a message asynchronously.
// contains filtered or unexported fields
}
SlackHook is a logrus Hook for dispatching messages to the specified channel on Slack.
Click to show internal directories.
Click to hide internal directories.
