parent
afbb7e18e1
commit
9a23725ce0
|
|
@ -4,12 +4,19 @@ This page summarizes a couple of rules to keep in mind when developing features
|
||||||
|
|
||||||
## Debugging and Logging
|
## Debugging and Logging
|
||||||
|
|
||||||
|
### General Logging
|
||||||
|
|
||||||
While developing feature or making changes in general, you can log error/warning/debug
|
While developing feature or making changes in general, you can log error/warning/debug
|
||||||
using `_log_error` `_log_warning` and `_log_debug`. This will help you solve problems quicker
|
using `_log_error` `_log_warning` and `_log_debug`. This will help you solve problems quicker
|
||||||
and also propagate important notes to other users of Bash-it.
|
and also propagate important notes to other users of Bash-it.
|
||||||
You can see the logs by using `bash-it doctor` command to reload and see the logs.
|
You can see the logs by using `bash-it doctor` command to reload and see the logs.
|
||||||
Alternatively, you can set `BASH_IT_LOG_LEVEL` to `BASH_IT_LOG_LEVEL_ERROR`, `BASH_IT_LOG_LEVEL_WARNING` or `BASH_IT_LOG_LEVEL_ALL`.
|
Alternatively, you can set `BASH_IT_LOG_LEVEL` to `BASH_IT_LOG_LEVEL_ERROR`, `BASH_IT_LOG_LEVEL_WARNING` or `BASH_IT_LOG_LEVEL_ALL`.
|
||||||
|
|
||||||
|
### Log Prefix/Context
|
||||||
|
|
||||||
|
You can define `BASH_IT_LOG_PREFIX` in your files in order to a have a constant prefix before your logs.
|
||||||
|
Note that we prefer to uses "tags" based logging, i.e `plugins: git: DEBUG: Loading git plugin`.
|
||||||
|
|
||||||
|
|
||||||
## Load Order
|
## Load Order
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ export BASH_IT_LOG_LEVEL_ALL=3
|
||||||
|
|
||||||
function _log_general()
|
function _log_general()
|
||||||
{
|
{
|
||||||
_about 'Internal function used for logging'
|
_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'
|
||||||
|
|
||||||
_has_colors && echo -e "$1$2${echo_normal}" || echo -e "$2"
|
message=${BASH_IT_LOG_PREFIX}$2
|
||||||
|
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _log_debug()
|
function _log_debug()
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,10 @@ load ../../lib/log
|
||||||
run _log_error "test test test"
|
run _log_error "test test test"
|
||||||
refute_output
|
refute_output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "lib log: logging with prefix" {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue