lib: log: Insert log level before message prefix

Also fix tests accordinly
pull/1628/head
Noah Gorny 2020-07-02 13:52:02 +03:00
parent 3069af37e0
commit 72dbfd2480
2 changed files with 7 additions and 6 deletions

View File

@ -18,10 +18,11 @@ function _log_general()
{ {
about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix'
param '1: color of the message' param '1: color of the message'
param '2: message to log' param '2: log level to print before the prefix'
param '3: message to log'
group 'log' group 'log'
message=${BASH_IT_LOG_PREFIX}$2 message=$2${BASH_IT_LOG_PREFIX}$3
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}" _has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}"
} }
@ -33,7 +34,7 @@ function _log_debug()
group 'log' group 'log'
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0
_log_general "${echo_green}" "DEBUG: $1" _log_general "${echo_green}" "DEBUG: " "$1"
} }
function _log_warning() function _log_warning()
@ -44,7 +45,7 @@ function _log_warning()
group 'log' group 'log'
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0
_log_general "${echo_yellow}" " WARN: $1" _log_general "${echo_yellow}" " WARN: " "$1"
} }
function _log_error() function _log_error()
@ -55,5 +56,5 @@ function _log_error()
group 'log' group 'log'
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0
_log_general "${echo_red}" "ERROR: $1" _log_general "${echo_red}" "ERROR: " "$1"
} }

View File

@ -82,5 +82,5 @@ load ../../lib/log
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL
BASH_IT_LOG_PREFIX="nice: prefix: " BASH_IT_LOG_PREFIX="nice: prefix: "
run _log_debug "test test test" run _log_debug "test test test"
assert_output "nice: prefix: DEBUG: test test test" assert_output "DEBUG: nice: prefix: test test test"
} }