Skip to content

codehakase/slack-logrus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

slack-logrus :walrus: Build Status godoc reference

📝📝 An Intuitive Logrus Hook for Slack

Sample

SlackLogrus ScreenShot

Installation

Using go get

$ go get -u github.com/codehakase/slack-logrus

Usage

Log Directly to A Slack Channel

package main
import (
  "github.com/codehakase/slack-logrus"
  "github.com/sirupsen/logrus"
)

func main() {

  logrus.SetOutput(os.Stderr)
  logrus.AddHook(&sl.Hook{
    SlackHookURL: "https://hooks.slack.com/services/xxxxxx/xxxxxx/xxxxxxx",
    Username:     "slack-logrus",
    IconEmoji:    ":mega:",
    WithLevels:   logrus.AllLevels,
    Channel:      "#dev-channel",
  })
  logrus.Info("Hey I'm test running my package!!!")
}

Send Extra Loggin Data

To send custom fields to aid understand logging use add an Options field

fields := map[string]interface{}{
  "hostname": "hakaselabs",
  "source":   os.Getenv("APISource"),
  "tag":      "test-tag",
}
logrus.AddHook(&slacklogrus.Hook{
  ...
  Options: fields,
})