logrus_slack

package module
v0.0.0-...-74aa3c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2017 License: MIT Imports: 5 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Slack Hooks for Logrus

GoDoc

Example

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/bluele/logrus_slack"
)

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",
		Timeout:        5 * time.Second, // request timeout for calling slack api
	})

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

Install

$ go get -u github.com/bluele/logrus_slack

Credits

This project based on slackrus

Author

Jun Kimura

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

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

func LevelThreshold

func LevelThreshold(l logrus.Level) []logrus.Level

LevelThreshold - Returns every logging level above and including the given parameter.

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.

func (*SlackHook) Fire

func (sh *SlackHook) Fire(e *logrus.Entry) error

Fire - Sent event to slack

func (*SlackHook) Levels

func (sh *SlackHook) Levels() []logrus.Level

Levels sets which levels to sent to slack

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址