Slack hook for Logrus
Switch branches/tags
Nothing to show
Clone or download
Latest commit f7aae32 May 19, 2018
Permalink
Failed to load latest commit information.
example rebase fixes Jun 10, 2017
.gitignore Addded extra fields Sep 25, 2017
LICENSE Add license May 18, 2018
README.md Extra fields README added Sep 26, 2017
levels.go rebase fixes Jun 10, 2017
slackrus.go Merge pull request #12 from hummerd/patch-1 May 18, 2018

README.md

slackrus

Slack hook for Logrus.

Fix import path

Use

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")
}

Extra fields

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,
})

Parameters

Required

  • HookURL

Optional

  • IconEmoji
  • IconURL
  • Username
  • Channel
  • Asynchronous
  • Extra

Installation

go get github.com/johntdyer/slackrus

Credits

Based on hipchat handler by nuboLAB