log: Fix logging to comply with the tests
parent
8d9f81fce0
commit
e6ebcda608
38
lib/log.bash
38
lib/log.bash
|
|
@ -16,10 +16,10 @@ function _has_colors()
|
||||||
|
|
||||||
function _log_general()
|
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: message to log'
|
||||||
_group 'log'
|
group 'log'
|
||||||
|
|
||||||
message=${BASH_IT_LOG_PREFIX}$2
|
message=${BASH_IT_LOG_PREFIX}$2
|
||||||
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}"
|
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}"
|
||||||
|
|
@ -27,33 +27,33 @@ function _log_general()
|
||||||
|
|
||||||
function _log_debug()
|
function _log_debug()
|
||||||
{
|
{
|
||||||
_about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ALL'
|
about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ALL'
|
||||||
_param '1: message to log'
|
param '1: message to log'
|
||||||
_example '$ _log_debug "Loading plugin git..."'
|
example '$ _log_debug "Loading plugin git..."'
|
||||||
_group 'log'
|
group 'log'
|
||||||
|
|
||||||
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return
|
[[ "$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()
|
||||||
{
|
{
|
||||||
_about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING'
|
about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING'
|
||||||
_param '1: message to log'
|
param '1: message to log'
|
||||||
_example '$ _log_warning "git binary not found, disabling git plugin..."'
|
example '$ _log_warning "git binary not found, disabling git plugin..."'
|
||||||
_group 'log'
|
group 'log'
|
||||||
|
|
||||||
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return
|
[[ "$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()
|
||||||
{
|
{
|
||||||
_about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR'
|
about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR'
|
||||||
_param '1: message to log'
|
param '1: message to log'
|
||||||
_example '$ _log_error "Failed to load git plugin..."'
|
example '$ _log_error "Failed to load git plugin..."'
|
||||||
_group 'log'
|
group 'log'
|
||||||
|
|
||||||
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return
|
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0
|
||||||
_log_general "${echo_red}" "ERROR: $1"
|
_log_general "${echo_red}" "ERROR: $1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
load ../test_helper
|
load ../test_helper
|
||||||
load ../../lib/composure
|
load ../../lib/composure
|
||||||
|
load ../../lib/log
|
||||||
|
|
||||||
cite _about _param _example _group _author _version
|
cite _about _param _example _group _author _version
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue