slackrus

package module
v0.0.0-...-80bc92d Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: Apache-2.0 Imports: 4 Imported by: 56

README

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

Documentation

Overview

Package slackrus provides a Slack hook for the logrus loggin package.

Index

Constants

View Source
const (
	VERISON = "0.0.3"
)

Project version

Variables

Supported log levels

Functions

func LevelThreshold

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

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

Types

type Filter

type Filter func(entry *logrus.Entry) bool

Filter is a filter applied to log entries to filter out any messages which are too noisy. The filter should return true if the message should be included, and false if not.

type SlackrusHook

type SlackrusHook 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
	// Filters are applied to messages to determine if any entry should not be send out.
	Filters      []Filter
	HookURL      string
	IconURL      string
	Channel      string
	IconEmoji    string
	Username     string
	Asynchronous bool
	Extra        map[string]interface{}
	Disabled     bool
	// SortFields if set to true will sort Fields before sending them to slack. By default they
	// are sorted in alphabetical order. For finer grained control, SortPriorities can be used.
	SortFields bool
	// SortPriorities if set will modify the straight alphabetical sort used when SortFields is set.
	// It is a map of field keys to sort priority, causing keys with higher priorities to appear first.
	// Any field field keys that do not appear in SortPriorities will appear after all those that do
	// and be sorted in alphabetical order.
	SortPriorities map[string]int
}

SlackrusHook is a logrus Hook for dispatching messages to the specified channel on Slack.

func (*SlackrusHook) Fire

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

Fire - Sent event to slack

func (*SlackrusHook) Levels

func (sh *SlackrusHook) 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