telelog

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 10 Imported by: 0

README

Telelog

Go Reference

Embed to app or tail a file, the log will send to your telegram (chat_id)

Telegram Notification

Installation

Embed to your app using Go Modules

go get github.com/codenoid/telelog

CLI version

go get github.com/codenoid/telelog/cmd/telelog

Usage

Example of recipient file content (text file) :

999838460
961268461
827957192

CMD Example :

you must set env var for cli version !

$ codenoid> telelog 
Telelog, make sure you already set these env : 
TELELOG_BOT_TOKEN
TELELOG_APP_NAME
TELELOG_DEBUG_MODE (optional)
TELELOG_RECIPIENT_LIST

$ codenoid> telelog -file ./path/to/error.log -level error

Code Example :

package main

import (
    "time"

    "github.com/codenoid/telelog"
)

func main() {
    logger := telelog.LoggerNew()

    // default TELELOG_BOT_TOKEN, unless you call SetToken
    logger.SetToken("1125121251:AAF2sfBCbKjag8LhUIAzf1mzk36BxcJ0Mvg")

    // default TELELOG_APP_NAME, unless you call SetAppName
    logger.SetAppName("Uploader Service")

    // default TELELOG_DEBUG_MODE, unless you call SetDebug
    // if true, any logger.Debug* log will be send 
    logger.SetDebug(false)

    // default TELELOG_RECIPIENT_LIST (single path to file), unless you call SetRecipient
    logger.SetRecipient("/path/to/text/file.txt", "/second/file/that/contain/chat_id.txt")

    // or reader
    f, _ := os.Open("file.txt")
    logger.SetRecipientFromReader(f)

    // or []byte
    logger.SetRecipientFromByte([]byte{"777000\n"})

    logger.Warn("Warning! your app will be error")
    logger.Error("yo, this is error, in 2sec your app will dead")
    time.Sleep(2*time.Second)
    logger.Fatal("lmaoo")

}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Documentation

Index

Constants

View Source
const (
	FATAL = "💥 [FATAL]"
	ERROR = "🥴 [ERROR]"
	WARN  = "⚠️ [WARN]"
	INFO  = "👀 [INFO]"
	DEBUG = "🤔 [DEBUG]"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger telelog logger instance

func LoggerNew

func LoggerNew(token ...string) *Logger

LoggerNew create new telelog Instance

func (*Logger) Debug

func (i *Logger) Debug(v ...interface{})

Debug print debug message to output if debug output enabled

func (*Logger) Debugf

func (i *Logger) Debugf(format string, v ...interface{})

Debugf print formatted debug message to output if debug output enabled

func (*Logger) Error

func (i *Logger) Error(v ...interface{})

Error print error message to output

func (*Logger) Errorf

func (i *Logger) Errorf(format string, v ...interface{})

Errorf print formatted error message to output

func (*Logger) Fatal

func (i *Logger) Fatal(v ...interface{})

Fatal print fatal message to output and quit the application with status 1

func (*Logger) Fatalf

func (i *Logger) Fatalf(format string, v ...interface{})

Fatalf print formatted fatal message to output and quit the application with status 1

func (*Logger) Info

func (i *Logger) Info(v ...interface{})

Info print informational message to output

func (*Logger) Infof

func (i *Logger) Infof(format string, v ...interface{})

Infof print formatted informational message to output

func (*Logger) SetAppName

func (i *Logger) SetAppName(name string)

SetAppName set application name

func (*Logger) SetDebug

func (i *Logger) SetDebug(debug bool)

SetDebug set debug

func (*Logger) SetEnableCallerInfo

func (i *Logger) SetEnableCallerInfo(callerInfo bool)

SetEnableCallerInfo extract caller information and show the info on log

func (*Logger) SetRecipientFromByte

func (i *Logger) SetRecipientFromByte(b []byte)

SetRecipientFromByte receive byte of file content

func (*Logger) SetRecipientFromFiles

func (i *Logger) SetRecipientFromFiles(files ...string)

SetRecipientFromFiles receive string of file path

func (*Logger) SetRecipientFromReader

func (i *Logger) SetRecipientFromReader(r io.Reader) error

SetRecipientFromReader read content from reader

func (*Logger) SetToken

func (i *Logger) SetToken(token string) error

SetToken change existing token if token are different initiate new i.bot instance if token are different

func (*Logger) Warn

func (i *Logger) Warn(v ...interface{})

Warn print warning message to output

func (*Logger) Warnf

func (i *Logger) Warnf(format string, v ...interface{})

Warnf print formatted warning message to output

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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