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
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
Use the package manager go get to install this package.
go get -u github.com/ibnumardini/logn
- make config file
logn_config.json
in your root project directory
{
"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
}
}
logn_is_active
used to actived or deactived logn package
logn_dir
used for set default log directory namelogn_default_loc
used for set default timezonelogn_print_console
used to print log at console
logn_tg_send
used to actived or deactived report warning/error log to telegramlogn_app_name
used to set title in report telegram messagelogn_tg_token
used for telegram bot tokenlogn_tg_chat_id
used for set where bot send report message
logn_is_zipped
used to actived or deactived automate zipped log in one monthlogn_dir_zip
used for set default log zip directory namelogn_del_old_dir
used to set automate deleting old zip directory after zipped
logn.InfoLog("hello world")
logn.WarningLog(fmt.Sprintf("%s\n", warningInfo))
logn.ErrorLog(fmt.Sprintln("error message!"))
logn.InfoLog()
used to make log type infologn.WarningLog()
used to make log type warninglogn.ErrorLog()
used to make log type error
- if you have complex string, you can format first using
fmt.Sprintf()
orfmt.Sprintln()
before input in the parameters
- set
logn.CronZip(1)
at your init func - set like this
./app logn_zip_run
when run your app
- fill in the parameter with the position of the argument according to what you set, param type is int
Let's build this Logn library to make it even better, see contributing guide here
Logn is under the MIT License