tglogger

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 3 Imported by: 0

README

Telegram logger

GoDoc

Logger to send message in telegram chats.
Package created for some log notification for pet/small projects.
It's not suitable for something like access.log on highloaded projects.

Features

  • Send messages to multiple chats
  • Set log level: debug | info | warn | error
  • Set custom labels for different levels
  • Set app_name, which will be displayed in a message
    (when use same chat for logs from different apps)

Example

package main

import tglog "github.com/quirel/telegram-logger"

func main() {
	token := "YOUR_TELEGRAM_BOT_TOKEN"
	chatIds := []int64{123123, 456456}

	// creates logger with level 'debug'
	logger, _ := tglog.NewLogger("debug", token, chatIds)
	// set name displayed in logs
	logger.SetName("MyApp")
	
	logger.Debug("Debug message") // "MyApp, 👾 DEBUG\nDebug message"
	logger.Info("Info message") // "MyApp, 🔵 INFO\nInfo message"
	logger.Warn("Warning message") // "MyApp, ⚠️ WARN\nWarning message"
	logger.Error("Error message") // "MyApp, ❌ ERROR\nError message"

	labels := tglog.LevelLabels{
		Debug: "dbg", Info: "inf", Warn: "wrn", Error: "err",
	}
	// Set not default labels for different log levels
	logger.SetLabels(&labels)
	logger.Debug("Debug message") // "MyApp, dbg\nDebug message"
}

Documentation

Overview

Package to send message in telegram chats. Package created for some log notification for pet/small projects. It's not suitable for something like access.log on highloaded projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LevelLabels

type LevelLabels struct {
	Debug string
	Info  string
	Warn  string
	Error string
}

LevelLabels specifies labels for different log Labels

type TgLogger

type TgLogger struct {
	TgBot      *tgbotapi.BotAPI
	ChatIdList []int64
	Labels     *LevelLabels
	Name       string
	Level      string
}

TgLogger allows to send logs into chat with telegram bot Level - Debug | Info | Warn | Error

func NewLogger

func NewLogger(level string, tgToken string, tgChatIds []int64) (*TgLogger, error)

NewLogger creates new TgLogger

func (*TgLogger) Debug

func (logger *TgLogger) Debug(msg string)

Debug sends Debug message, depends on log Level

func (*TgLogger) Error

func (logger *TgLogger) Error(msg string)

Error sends Error message

func (*TgLogger) Info

func (logger *TgLogger) Info(msg string)

Info sends Info message, depends on log Level

func (*TgLogger) Log

func (logger *TgLogger) Log(msg string)

Log sends simple message

func (*TgLogger) Send

func (logger *TgLogger) Send(msg string, chatId int64) error

Send sends message. Can return Error

func (*TgLogger) SetLabels added in v1.0.0

func (logger *TgLogger) SetLabels(labels *LevelLabels)

func (*TgLogger) SetName

func (logger *TgLogger) SetName(name string)

SetName sets Name for logger displayed in message

func (*TgLogger) Warn

func (logger *TgLogger) Warn(msg string)

Warn sends Warn message, depends on log Level

Jump to

Keyboard shortcuts

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