glog

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 8 Imported by: 0

README

Glog

(This repo is a hard fork of Tele [https://github.com/4FR4KO-POVELECKO/glog]).

Glog is a small console,file and Telegram Bot logger for Go.

Logging in:

  • Telegram bot (in-progress)
  • File .log
  • Terminal

Installation

go get -u github.com/signalify.in/glog

Examples

First, create bot in BotFather.

Start:

package main

import (
	"github.com/signalify.in/glog"
)

func main() {
	// Create new logger
	logger := glog.New()

	// Log to file 
	dirLevels := []glog.Level{ // choose levels
		glog.Panic,
		glog.Fatal,
		glog.Error,
		glog.Warning,
		glog.Info,
		glog.Debug,
		glog.Trace,
	}

	err := logger.NewDir("./log", dirLevels)
	if err != nil {
		logger.Error(err)
	}

	// Log to telegram bot
	botLevels := []glog.Level{ // choose levels
		glog.Panic,
		glog.Fatal,
		glog.Error,
		glog.Warning,
		glog.Info,
		glog.Debug,
		glog.Trace,
	}

	err = logger.NewBot("BOT_TOKEN", botLevels)
	if err != nil {
		logger.Error(err)
	}
}

Usage:

logger.Log("./log/trace.Log", glog.Info, "text")
logger.Trace("text")
logger.Debug("text")
logger.Info("text")
logger.Error("text")
logger.Warning("text")
logger.Fatal("text")
logger.Panic("text")

Levels:

package glog

type Level string

const (
	Panic   Level = "PANIC:"
	Fatal   Level = "FATAL:"
	Error   Level = "ERROR:"
	Warning Level = "WARNING:"
	Info    Level = "INFO:"
	Debug   Level = "DEBUG:"
	Trace   Level = "TRACE:"
)

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 (
	LevelPanic uint8 = iota + 1
	LevelFatal
	LevelError
	LevelWarning
	LevelInfo
	LevelDebug
	LevelTrace
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level string
const (
	Panic   Level = "PANIC:"
	Fatal   Level = "FATAL:"
	Error   Level = "ERROR:"
	Warning Level = "WARNING:"
	Info    Level = "INFO:"
	Debug   Level = "DEBUG:"
	Trace   Level = "TRACE:"
)

type Logger

type Logger struct {
	Bot       *telegrambot
	BotLevels []Level

	DirPath   string
	DirLevels []Level
	Lot       bool // Lot - Log on Terminal
	LogPrefix string
}

func New

func New(level uint8, otherArgs ...string) *Logger

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Log

func (l *Logger) Log(path string, level Level, args ...interface{})

func (*Logger) LogToFile

func (l *Logger) LogToFile(path string, level Level, args ...interface{})

Loggers

func (*Logger) NewBot

func (l *Logger) NewBot(token string, chatId int, levels []Level) error

func (*Logger) NewDir

func (l *Logger) NewDir(path string, levels []Level) error

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) Warning

func (l *Logger) Warning(args ...interface{})

Jump to

Keyboard shortcuts

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