From 02c13b7921ac86e8ec4742ce82c9c883f678c3da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 25 Jul 2021 20:02:48 -0700 Subject: [PATCH] lib/log: handle undefined variables If the user hasn't defined BASH_IT_LOG_LEVEL, then the integer comparison fails. Handle it by defaulting to '1'. If lib/log is loaded improperly, the BASH_IT_LOG_PREFIX may be undefined. Unlikely, but no harm in handling it too. Likewise, if no theme is loaded, then $echo_green, $echo_normal, et al are not defined. --- lib/log.bash | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) mode change 100644 => 100755 lib/log.bash diff --git a/lib/log.bash b/lib/log.bash old mode 100644 new mode 100755 index 105c9064..401fa3fa --- a/lib/log.bash +++ b/lib/log.bash @@ -22,8 +22,8 @@ function _log_general() param '3: message to log' group 'log' - message=$2${BASH_IT_LOG_PREFIX}$3 - _has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}" + message=$2${BASH_IT_LOG_PREFIX:-default: }$3 + _has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}" } function _log_debug() @@ -33,8 +33,8 @@ function _log_debug() example '$ _log_debug "Loading plugin git..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 - _log_general "${echo_green}" "DEBUG: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 + _log_general "${echo_green:-}" "DEBUG: " "$1" } function _log_warning() @@ -44,7 +44,7 @@ function _log_warning() example '$ _log_warning "git binary not found, disabling git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 _log_general "${echo_yellow}" " WARN: " "$1" } @@ -55,6 +55,6 @@ function _log_error() example '$ _log_error "Failed to load git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 - _log_general "${echo_red}" "ERROR: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-1}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 + _log_general "${echo_red:-}" "ERROR: " "$1" }