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-

  1. Download the Bash logger tar file. Download Bash Logger
  2. Untar it.
  3. Keep the two files (bash_logger.sh and bash_logger.conf) file wherever you want. Better to keep it in your project directory.
  4. Edit the bash_logger.conf file according to your requirement.
  5. source these two files from your main script file. Then you are ready.
  6. If you want to give a debug log use function DEBUG if you want INFO use INFO function so on.
  7. 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

To Download -

Download Bash Logger