Project

General

Profile

« Previous | Next » 

Revision 9305

lib/sh/util.sh: logging: added log+/-, which take a variable log_level step, and use them in log++/--

View differences:

lib/sh/util.sh
179 179
# for unfiltered messages, the log_level is 0 (i.e. still output at verbosity=0)
180 180
# to view a message's log_level, count the # of + signs before it in the output
181 181

  
182
alias PS4_prefix_n='str="${PS4:0:1}" n=$1 repeat'
183

  
184
fi # load new aliases
185
if self_being_included; then
186

  
182 187
# usage: in func:      log++; ...         OR  log_local; "log++"; ...
183 188
#        outside func: log++; ...; log--
184 189
#        before cmd:   log++ cmd...
185 190
# without a cmd, "$@" expands to nothing and assignments are applied to caller
186
log++() { PS4="${PS4:0:1}$PS4"    verbosity=$((verbosity-1)) "$@"; }
187
log--() { PS4="${PS4#${PS4:0:1}}" verbosity=$((verbosity+1)) "$@"; }
191
# "${@:2}" expands to all of $@ after *1st* arg, not 2nd ($@ indexes start at 1)
192
log+()  { PS4="$(PS4_prefix_n)$PS4" verbosity=$((verbosity-$1)) "${@:2}"; }
193
log-()  { PS4="${PS4:$1}"           verbosity=$((verbosity+$1)) "${@:2}"; }
194
log++() { log+ 1 "$@"; }
195
log--() { log- 1 "$@"; }
188 196
alias log_local='declare PS4="$PS4" verbosity="$verbosity"'
197
alias log+='log_local; "log+" ' # last space alias-expands next word
198
alias log-='log_local; "log-" ' # last space alias-expands next word
189 199
alias log++='log_local; "log++" ' # last space alias-expands next word
190 200
alias log--='log_local; "log--" ' # last space alias-expands next word
191 201

  

Also available in: Unified diff