Project

General

Profile

« Previous | Next » 

Revision 9373

lib/sh/util.sh: logging: log+: support negative log_level adjustments. log-: use log+ with the negative of its argument

View differences:

lib/sh/util.sh
232 232
#        before cmd:   log++ cmd...
233 233
# without a cmd, "$@" expands to nothing and assignments are applied to caller
234 234
# "${@:2}" expands to all of $@ after *1st* arg, not 2nd ($@ indexes start at 1)
235
log+()  { PS4="$(PS4_prefix_n)$PS4" verbosity=$((verbosity - $1)) "${@:2}"; }
236
log-()  { PS4="${PS4:$1}"           verbosity=$((verbosity + $1)) "${@:2}"; }
235
log+()
236
{
237
	# no local vars because w/o cmd, assignments should be applied to caller
238
	PS4="$(if test "$1" -gt 0; then echo "$(PS4_prefix_n)$PS4"
239
		else echo "${PS4:$1}"; fi)" \
240
	verbosity=$((verbosity - $1)) "${@:2}"
241
}
242
log-() { log+ $((-($1))); }
237 243
log++() { log+ 1 "$@"; }
238 244
log--() { log- 1 "$@"; }
239 245
alias log_local='declare PS4="$PS4" verbosity="$verbosity"'

Also available in: Unified diff