Revision 12821
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/lib/sh/util.sh | ||
---|---|---|
414 | 414 |
: "${verbosity=1}" # default |
415 | 415 |
: "${verbosity:=0}" # ensure non-empty |
416 | 416 |
export verbosity # propagate to invoked commands |
417 |
export PS4 # follows verbosity, so also propagate this |
|
418 | 417 |
|
419 | 418 |
is_outermost="$(! isset log_level; exit2bool)" # if util.sh env not yet set up |
420 | 419 |
|
421 | 420 |
# set log_level |
422 | 421 |
: "${log_level=$(( ${#PS4}-1 ))}" # defaults to # non-space symbols in PS4 |
423 | 422 |
export log_level # propagate to invoked commands |
423 |
export PS4 # follows log_level, so also propagate this |
|
424 | 424 |
|
425 | 425 |
verbosity_int() { round_down "$verbosity"; } |
426 | 426 |
|
... | ... | |
458 | 458 |
# no local vars because w/o cmd, assignments should be applied to caller |
459 | 459 |
PS4="$(str="${PS4:0:1}" n=$((log_level+$1-1)) repeat)${PS4: -2}"; \ |
460 | 460 |
log_level=$((log_level+$1)) \ |
461 |
verbosity="$(float+int "$verbosity" "-$1")" "${@:2}"
|
|
461 |
"${@:2}" |
|
462 | 462 |
} |
463 | 463 |
log-() { log+ "-$1" "${@:2}"; } |
464 | 464 |
log++() { log+ 1 "$@"; } |
465 | 465 |
log--() { log- 1 "$@"; } |
466 | 466 |
log!() { log- "$log_level" "$@"; } # force-displays next log message |
467 |
alias log_local=\ |
|
468 |
'declare PS4="$PS4" log_level="$log_level" verbosity="$verbosity"' |
|
467 |
alias log_local='declare PS4="$PS4" log_level="$log_level"' |
|
469 | 468 |
alias log+='log_local; "log+"' # don't expand next word because it's not a cmd |
470 | 469 |
alias log++='log_local; "log++" ' # last space alias-expands next word |
471 | 470 |
alias log--='log_local; "log--" ' # last space alias-expands next word |
... | ... | |
496 | 495 |
fi # load new aliases |
497 | 496 |
if self_being_included; then |
498 | 497 |
|
499 |
can_log() { test "$(verbosity_int)" -gt 0; }
|
|
498 |
can_log() { test "$log_level" -le "$(verbosity_int)"; }
|
|
500 | 499 |
# verbosity=0 turns off all logging |
501 | 500 |
|
502 | 501 |
can_highlight_msg() { test "$log_level" -le 1; } |
Also available in: Unified diff
lib/sh/util.sh: $verbosity: stay constant at what the user set it to instead of changing in tandem with $log_level, to facilitate debugging verbosity/log_level-related issues