telegram_hook

package module
v0.0.0-...-aec4924 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 8 Imported by: 0

README

Telegam Logrus Hook

Go Report Card GoDoc

This hook emits log messages (and corresponding fields) to the Telegram API for logrus. Currently this hook will only emit messages for the following levels:

  • ERROR
  • FATAL
  • PANIC

Installation

Install the package with:

go get github.com/rossmcdonald/telegram_hook

Usage

See the tests for working examples. Also:

import (
	log "github.com/Sirupsen/logrus"
	"github.com/rossmcdonald/telegram_hook"
)

func main() {
	hook, err := telegram_hook.NewTelegramHook(
		"MyCoolApp",
		"MYTELEGRAMTOKEN",
		"@mycoolusername",
	)
	if err != nil {
		log.Fatalf("Encountered error when creating Telegram hook: %s", err)
	}
	log.AddHook(hook)
	
	// Receive messages on failures
	log.Errorf("Uh oh...")
	...
	
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TelegramHook

type TelegramHook struct {
	AppName string
	// contains filtered or unexported fields
}

TelegramHook to send logs via the Telegram API.

func NewTelegramHook

func NewTelegramHook(appName, authToken string, chatID int) (*TelegramHook, error)

NewTelegramHook creates a new instance of a hook targeting the Telegram API.

func (*TelegramHook) Fire

func (hook *TelegramHook) Fire(entry *logrus.Entry) error

Fire emits a log message to the Telegram API.

func (*TelegramHook) Levels

func (hook *TelegramHook) Levels() []logrus.Level

Levels returns the log levels that the hook should be enabled for.

Jump to

Keyboard shortcuts

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