Created
December 23, 2015 08:25
-
-
Save tonybaines/0ad3040a9e3a55ef5e6b to your computer and use it in GitHub Desktop.
Useful bash scripting functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# foundation function for the actual log-functions to build on | |
function _log { | |
echo "[$(date +%Y%m%d-%T)] $1" | |
} | |
# functions for the different log levels | |
function log_debug { | |
# debug messages need to be enabled through an environment varaible | |
if [ $DEBUG ] | |
then | |
_log "DEBUG: $1" | |
fi | |
} | |
function log_info { | |
_log "INFO: $1" | |
} | |
function log_warn { | |
_log "WARN: $1" | |
} | |
function log_error { | |
_log "ERROR $1" | |
} | |
# For when the process needs to exit with an error message | |
function die() { | |
log_error "$1" | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use
To show debug messages