Bash Logger designed to incorporate PSR-3 compliance.
- Dean Rather
- Hexosse
source the bash-logger.sh script at the beginning of any Bash program.
#!/bin/bashsource /path/to/bash-logger.sh
INFO "This is a test info log"Function names are in CAPS as not to conflict with the
infofunction andalertaliases.
Bash Logger supports the logging levels described by RFC 5424.
DEBUG Detailed debug information.
INFO Interesting events. Examples: User logs in, SQL logs.
NOTICE Normal but significant events.
WARNING Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
ERROR Runtime errors that do not require immediate action but should typically be logged and monitored.
CRITICAL Critical conditions. Example: Application component unavailable, unexpected exception.
ALERT Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
EMERGENCY Emergency: system is unusable.
An additional level OFF is added to completely remove messages from the console.
However, messages are still logged to file.
By default:
- Logs are displayed in colour
- Logs are written to
$HOME/bash-logger.log - Logs from pipe available
- error level logs and above
exitwith an error code
The colours, logfile, default behavior, and log-level behavior can all be overwritten, see examples.sh for examples.


