tglog

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

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 6 Imported by: 0

README

TG notify

Simple go library to add logrus logging hook to send error/fatal/panic/warn messages to telegram.

Can be connected to your service by providing:

  • Dev telegram bot token (token of dev bot, don't pass regular ones)
  • Connection password (will be asked on bot connection)
package main

import (
	"time"

	"github.com/sirupsen/logrus"
	"codeberg.org/dancheg97/tglog"
)

func main() {
	_, err := tglog.AddTelegramLogger("telegram:token", "connect_password")
	if err != nil {
		panic(err)
	}

	for {
		time.Sleep(time.Second * 10)
		logrus.Error("error message sent")
		time.Sleep(time.Second)
		logrus.Warn("warn message sent")

		logrus.WithFields(logrus.Fields{
			"uno":  "due",
			"hehe": "hehe1",
		}).Error("test")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTelegramLogger

func AddTelegramLogger(token, password string) (*logrus.Logger, error)

This function will add logging errors to telegram channel, returning modified version of logrus logger.

Types

type TgHook

type TgHook struct {
	Bot       *tgbotapi.BotAPI
	Receivers map[int64]struct{}
	sync.Mutex
}

func (*TgHook) Fire

func (h *TgHook) Fire(e *logrus.Entry) error

func (*TgHook) Levels

func (h *TgHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

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