rocketrus

package module
v0.0.0-...-6b77de1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 7 Imported by: 0

README

rocketrus

RocketChat hook for Logrus.

Use

package main

import (
	"log"
	"time"

	"github.com/miraclesu/rocketrus"
	"github.com/sirupsen/logrus"
)

func main() {
	hook := &rocketrus.RocketrusHook{
		HookURL: "http://localhost:3000",
		Channel: "general",

		NotifyUsers: []string{"miracle", "yuhcwl"},
		AcceptedLevels: rocketrus.LevelThreshold(logrus.DebugLevel),

		Email:    "suchuangji@gmail.com",
		Password: "gopher",

		Duration: -1,
		Batch:    1,
	}
	if err := hook.Run(); err != nil {
		log.Fatalln(err.Error())
	}

	logrus.AddHook(hook)
	logrus.SetLevel(logrus.DebugLevel)

	logrus.Warn("warn")
	logrus.Info("info")
	logrus.Debug("debug")
	time.Sleep(1 * time.Second)
}

Parameters

Required
  • HookURL
  • Channel
  • UserID & Token or Email & Password
Optional
  • AcceptedLevels
  • Disabled
  • Title
  • Alias
  • Emoji
  • Avatar
  • NotifyUsers
  • Duration
  • Batch

Installation

go get github.com/miraclesu/rocketrus

Credits

slackrus

Documentation

Overview

Package rocketrus provides a RocketChat hook for the logrus loggin package.

Index

Constants

This section is empty.

Variables

View Source
var (
	NotRunningErr = fmt.Errorf("RocketrusHook doesn't running, please call Run function first")
)

Functions

func LevelThreshold

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

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

Types

type RocketrusHook

type RocketrusHook struct {
	HookURL string
	Channel string
	// If UserID and Token are present, will use UserID and Token auth rocket.chat API
	// otherwise Email and the Password are mandatory.
	UserID   string
	Token    string
	Email    string
	Password string

	// Messages with a log level not contained in this array
	// will not be dispatched. If nil, all messages will be dispatched.
	AcceptedLevels []logrus.Level
	Disabled       bool
	// Title name for log
	Title  string
	Alias  string
	Emoji  string
	Avatar string
	// Notify users with @user in RocketChat.
	NotifyUsers []string
	// batch send message duration, uion/second, default is 10 seconds
	// if duration is negative, RocketrusHook will block ticker message send
	// e.g. Duration:10, Batch:8 means received more than(include equal) 8 logs in 10 seconds will send as one message to RocketChat immediately, or after 10 seconds received any(>=1) logs will send as one message to RocketChat.
	// e.g. Duration:-1, Batch:8 means only received more than(include equal) 8 logs then send to RocketChat
	Duration int64
	// batch send message, default is 8
	Batch int

	*models.UserCredentials
	*rest.Client
	// contains filtered or unexported fields
}

RocketrusHook is a logrus Hook for dispatching messages to the specified channel on RocketChat.

func (*RocketrusHook) Fire

func (rh *RocketrusHook) Fire(e *logrus.Entry) error

Fire - Sent event to RocketChat

func (*RocketrusHook) Levels

func (rh *RocketrusHook) Levels() []logrus.Level

Levels sets which levels to sent to RocketChat

func (*RocketrusHook) Run

func (rh *RocketrusHook) Run() error

Run start RocketrusHook message processor

Jump to

Keyboard shortcuts

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