logn

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 13 Imported by: 0

README

GitHub tag (latest by date) GitHub

About Logn

Logn :/logen/ is a simple log management library for go app ツ, with several features provided such as :

  • Generate log by day
  • Generate log by type
  • Report log type Warning / Error to telegram via bot
  • Zipping log data every one month
  • Deleting old log directory

Logn Tree

go-app
│   main
│
├───log
│    └───2020
│        └───12
│            ├───01
│            │   info.log
│            │   warning.log
│            │   error.log
│            ├───02
│            │   info.log
│            │   warning.log
│            │   error.log
│
└───log_zip
    ├───2019
    │   log_12_2019.zip
    ├───2020
    │   log_01_2020.zip

Installation

Use the package manager go get to install this package.

go get -u github.com/ibnumardini/logn

Configuration

{
  "logn_is_active": true,
  "log": {
    "logn_dir": "log/",
    "logn_default_loc": "Asia/Jakarta",
    "logn_print_console": true
  },
  "tg": {
    "logn_tg_send": false,
    "logn_app_name": "Logn-App LOG",
    "logn_tg_token": "1416xxxxx:AAF3VOBjt7rIeO4tUL_dHxG0qxxxxxxxxx",
    "logn_tg_chat_id": "-4947xxxxx"
  },
  "zip": {
    "logn_is_zipped": false,
    "logn_dir_zip": "log_zip/",
    "logn_del_old_dir": false
  }
}

Config description

  • logn_is_active used to actived or deactived logn package
log
  • logn_dir used for set default log directory name
  • logn_default_loc used for set default timezone
  • logn_print_console used to print log at console
telegram
  • logn_tg_send used to actived or deactived report warning/error log to telegram
  • logn_app_name used to set title in report telegram message
  • logn_tg_token used for telegram bot token
  • logn_tg_chat_id used for set where bot send report message
zip
  • logn_is_zipped used to actived or deactived automate zipped log in one month
  • logn_dir_zip used for set default log zip directory name
  • logn_del_old_dir used to set automate deleting old zip directory after zipped

Usage

logn.InfoLog("hello world")
logn.WarningLog(fmt.Sprintf("%s\n", warningInfo))
logn.ErrorLog(fmt.Sprintln("error message!"))

Usage description

  • logn.InfoLog() used to make log type info
  • logn.WarningLog() used to make log type warning
  • logn.ErrorLog() used to make log type error
parameter
  • if you have complex string, you can format first using fmt.Sprintf() or fmt.Sprintln() before input in the parameters

Zipping log using cron

  • set logn.CronZip(1)at your init func
  • set like this ./app logn_zip_run when run your app
parameter
  • fill in the parameter with the position of the argument according to what you set, param type is int

Contributing

Let's build this Logn library to make it even better, see contributing guide here

License

Logn is under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CronZip added in v0.3.0

func CronZip(argsPos int) error

CronZip used for run logn zip automate with cron

func ErrorLog

func ErrorLog(logMessage interface{}) error

ErrorLog used for log type error

func InfoLog

func InfoLog(logMessage interface{}) error

InfoLog used for log type info

func WarningLog

func WarningLog(logMessage interface{}) error

WarningLog used for log type warning

Types

type Config added in v0.4.0

type Config struct {
	LognIsActive bool `json:"logn_is_active"`
	Log          Log  `json:"log"`
	Tg           Tg   `json:"tg"`
	Zip          Zip  `json:"zip"`
}

type Log added in v0.4.0

type Log struct {
	LognDir          string `json:"logn_dir"`
	LognDefaultLoc   string `json:"logn_default_loc"`
	LognPrintConsole bool   `json:"logn_print_console"`
}

type Tg added in v0.4.0

type Tg struct {
	LognAppName  string `json:"logn_app_name"`
	LognTgSend   bool   `json:"logn_tg_send"`
	LognTgToken  string `json:"logn_tg_token"`
	LognTgChatId string `json:"logn_tg_chat_id"`
}

type Zip added in v0.4.0

type Zip struct {
	LognIsZipped  bool   `json:"logn_is_zipped"`
	LognDirZip    string `json:"logn_dir_zip"`
	LognDelOldDir bool   `json:"logn_del_old_dir"`
}

Jump to

Keyboard shortcuts

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