lib: log: Insert log level before message prefix
Also fix tests accordinlypull/1628/head
parent
3069af37e0
commit
72dbfd2480
11
lib/log.bash
11
lib/log.bash
|
|
@ -18,10 +18,11 @@ function _log_general()
|
|||
{
|
||||
about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix'
|
||||
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'
|
||||
|
||||
message=${BASH_IT_LOG_PREFIX}$2
|
||||
message=$2${BASH_IT_LOG_PREFIX}$3
|
||||
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}"
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ function _log_debug()
|
|||
group 'log'
|
||||
|
||||
[[ "$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()
|
||||
|
|
@ -44,7 +45,7 @@ function _log_warning()
|
|||
group 'log'
|
||||
|
||||
[[ "$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()
|
||||
|
|
@ -55,5 +56,5 @@ function _log_error()
|
|||
group 'log'
|
||||
|
||||
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0
|
||||
_log_general "${echo_red}" "ERROR: $1"
|
||||
_log_general "${echo_red}" "ERROR: " "$1"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,5 +82,5 @@ load ../../lib/log
|
|||
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL
|
||||
BASH_IT_LOG_PREFIX="nice: prefix: "
|
||||
run _log_debug "test test test"
|
||||
assert_output "nice: prefix: DEBUG: test test test"
|
||||
assert_output "DEBUG: nice: prefix: test test test"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue