Giter Site home page Giter Site logo

slackrus's Introduction

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

slackrus's People

Contributors

amanbolat avatar cgilling avatar johntdyer avatar philk avatar rubensayshi avatar tg avatar ybbus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slackrus's Issues

Even if JSON not set, still seeing some logging from the library in JSON on STDOUT

With this code:

func setLogging() {
    log.SetLevel(log.DebugLevel)
    log.AddHook(&slackrus.SlackrusHook{
        HookUrl:        "https://hooks.slack.com/services/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",
        AcceptedLevels: slackrus.LevelThreshold(log.DebugLevel),
        Channel:        "#tropoconf-log",
        IconEmoji:      ":ghost:",
        Username:       "tropoconf",
    })
}

I see this logging on my STDOUT:

{"text":"","username":"tropoconf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Listening on 3000...","text":"Listening on 3000...","pretext":"","color":"good","fields":null}]}
{"text":"","username":"conf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Ready!","text":"Ready!","pretext":"","color":"good","fields":null}]}

INFO[0001] Ready!                                       
INFO[0001] Listening on 3000...                         

{"text":"","username":"conf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Full request","text":"Full request","pretext":"","color":"good","fields":null}]}

INFO[0005] Full request                   
               requestBody=token=foo&team_id=T123&team_domain=tropo&channel_id=abcdef&channel_name=conf-command-testing&user_id=U2&user_name=jsgoecke&command=%2Fcf&text=help
{"text":"","username":"conf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Request received","text":"Request received","pretext":"","color":"good","fields":null}]}

INFO[0006] Request received                              active=false id=abcdef name=conf-command-testing

Where I see interleaving of the JSON with my logging, but I have not set JSON anywhere and am expecting only the standard output in this case.

case-insensitive import collision for logrus

It looks like Sirupsen/logrus has updated the import path to have a lowercase "s", I am now seeing this error

case-insensitive import collision: "github.com/Sirupsen/logrus" and "github.com/sirupsen/logrus"

Extra fields [enhancement]

Description

Add some extra fields that will be only sent by hook, but will not change origin entry.
Idea was taken from https://github.com/gemnasium/logrus-postgresql-hook

How to

// Add Extra field
type SlackrusHook struct {
	Extra          map[string]interface{}
}
// Function to create new entry with extra fields
func (sh *SlackrusHook) newEntry(entry *logrus.Entry) *logrus.Entry {
	//return newEntry
}

If you like it, I can open pull request.

New Trace log level in logrus

Hello, I'm just opening this issue to let you know, the next release of logrus (v1.2.0) will add a new trace level named Trace below Debug.
Here is the PR for reference sirupsen/logrus#844
You may want to take into account this new level.

If logrus.SetFormatter(&logrus.JSONFormatter{}) is set, logging still default in Slack

I currently set my logging this way:

func setLogging() {
    log.SetFormatter(&log.JSONFormatter{})
    log.SetLevel(log.DebugLevel)
    log.AddHook(&slackrus.SlackrusHook{
        HookUrl:        "https://hooks.slack.com/services/foo/bar",
        AcceptedLevels: slackrus.LevelThreshold(log.DebugLevel),
        Channel:        "#conf-log",
        IconEmoji:      ":ghost:",
        Username:       "conf",
    })
}

And get this logging on STDOUT:

{"text":"","username":"conf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Listening on 3000...","text":"Listening on 3000...","pretext":"","color":"good","fields":null}]}
{"text":"","username":"tropoconf","icon_url":"","icon_emoji":":ghost:","channel":"#conf-log","unfurl_links":false,"attachments":[{"fallback":"Ready!","text":"Ready!","pretext":"","color":"good","fields":null}]}
{"level":"info","msg":"Ready!","time":"2015-01-05T14:56:12-08:00"}
{"level":"info","msg":"Listening on 3000...","time":"2015-01-05T14:56:12-08:00"}

But, I only logged the last two "info" messages, not the first two. Further, when set to JSON, I see my messages locally in JSON, but then only see this in the Slack channel:

Listening on 3000...

Ready!

I would expect to see JSON in my Slack chat with this setting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.