

GitHub - nk412/tinylogger: Lightweight logging framework for bash
source link: https://github.com/nk412/tinylogger
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

tinylogger
An extremely lightweight logging framework for BASH scripts. Developed and tested on MacOS. This should work on any BASH platform.
Log levels
It supports four levels, default being INFO
.
ERROR > WARN > INFO > DEBUG
Usage
Source the tinylogger.bash
file, and use the tlog
method.
The first argument is the level, and the second the log message.
source tinylogger.bash
tlog warn "This is a warning"
See demo.sh
for more.
You can control the logging level while calling a script by setting the LOGGER_LVL
argument.
$ LOGGER_LVL=warn ./demo.sh
2017-11-07 19:05:30 - WARN - This is a scary warning
2017-11-07 19:05:30 - ERROR - Something terrible has happened
$ LOGGER_LVL=debug ./demo.sh
2017-11-07 19:05:52 - DEBUG - first line of script
2017-11-07 19:05:52 - INFO - Starting script ./demo.sh
2017-11-07 19:05:52 - DEBUG - another debug statement
2017-11-07 19:05:52 - INFO - Current time is Tue 7 Nov 2017 19:05:52 GMT
2017-11-07 19:05:52 - WARN - This is a scary warning
2017-11-07 19:05:52 - DEBUG - do you like these debug statements?
2017-11-07 19:05:52 - ERROR - Something terrible has happened
2017-11-07 19:05:52 - DEBUG - end of script
2017-11-07 19:05:52 - INFO - Script completed, go home
You can set LOGGER_LVL=none
to disable all logging.
Timestamp customisation
Underneath, the date
command is used to display the timestamp. Simply set the LOGGER_FMT
to any valid format supported by date
.
$ LOGGER_LVL=warn LOGGER_FMT=%s ./demo.sh
1510081622 - WARN - This is a scary warning
1510081622 - ERROR - Something terrible has happened
License
Recommend
-
51
README.md
-
62
-
31
README.md www.sh Web framework in Bash DO NOT USE THIS IN ANY PUBLIC FACING SERVER. THIS IS NOT SECURE. FOR...
-
74
README.md English | ç®€ä½“ä¸æ–‡ dva
-
17
README.md Willow
-
21
Disclaimer Bango is a PHP experiment created as a university project of a student (me). It was created within a week, please note that this is not a production-ready framework, there are several security flaws and issues that mus...
-
6
What's this? This is a extension of Emacs provides logging framework for Elisp. Feature Define function for logging automatically Write the following sexp in your elisp file. (log4e:deflogger "h...
-
8
Files Permalink Latest commit message Commit time
-
4
Files Permalink Latest commit message Commit time
-
5
bashin A minimal pure BASH framework Bashin is a framework intended to be as minimal and clean as possible. Wrote in pure BASH, bashin aims for speed and ingenuity Many scripters resort to external commands that...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK