Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nk412/tinylogger
Lightweight logging framework for bash
https://github.com/nk412/tinylogger
bash logging logging-library shell-script
Last synced: 29 days ago
JSON representation
Lightweight logging framework for bash
- Host: GitHub
- URL: https://github.com/nk412/tinylogger
- Owner: nk412
- License: mit
- Created: 2017-11-07T18:21:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-16T13:43:30.000Z (over 3 years ago)
- Last Synced: 2024-04-09T02:44:22.029Z (8 months ago)
- Topics: bash, logging, logging-library, shell-script
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 39
- Watchers: 2
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli-tui-software - nk412/tinylogger - Lightweight logging framework for bash (<a name="shell"></a>shell)
README
# 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`](./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
MIT