This is a logger for shell script.
Key Features-
- Easy to use.
- Different Log Level
- Different log files for different log levels.
- Output of the log is very easy to understand.
How to use-
- Download the Bash logger tar file. Download Bash Logger
- Untar it.
- Keep the two files (bash_logger.sh and bash_logger.conf) file wherever you want. Better to keep it in your project directory.
- Edit the bash_logger.conf file according to your requirement.
- source these two files from your main script file. Then you are ready.
- If you want to give a debug log use function DEBUG if you want INFO use INFO function so on.
- In that tar file. There is a test.sh file which gives an example. the code is as follows.
==============================================================
#!/bin/sh
# Source the logger
source bash_logger.sh
source bash_logger.conf
# test function
function testFunction()
{
DEBUG “debug log”
INFO “info log”
ERROR “error log”
}
testFunction $@
==============================================================
The Log output will be –
DEBUG [25-Mar-09 13:12:51] test.sh:testFunction:11 – debug log
INFO [25-Mar-09 13:12:51] test.sh:testFunction:12 – info log
ERROR [25-Mar-09 13:12:51] test.sh:testFunction:13 – error log

Leave a comment
Comments feed for this article