Project

General

Profile

« Previous | Next » 

Revision 9212

lib/sh/util.sh: added $log_fd and use it instead of 2 where the log_fd is intended

View differences:

util.sh
149 149

  
150 150
### logging
151 151

  
152
disable_logging() { exec 2>/dev/null; }
152
log_fd=2 # stderr
153 153

  
154
disable_logging() { eval exec "$log_fd>/dev/null"; }
155

  
154 156
if test "$explicit_errors_only"; then verbosity=0; fi # hide startup logging
155 157

  
156 158
# set verbosity
......
179 181

  
180 182
can_log() { test "$verbosity" -gt 0; } # verbosity=0 turns off all logging
181 183

  
182
log() { if can_log; then echo "$log_indent$PS4$1" >&2; fi; }
184
log() { if can_log; then echo "$log_indent$PS4$1" >&"$log_fd"; fi; }
183 185

  
184 186
# usage: symbol=... log_custom msg
185 187
log_custom() { local PS4="${PS4%[^ ] }$symbol "; log "$@"; }
186 188

  
187
log_err() { symbol=! verbosity=1 log_custom "$@" 2>&"$err_fd"; }
189
log_err() { symbol=! verbosity=1 log_fd="$err_fd" log_custom "$@"; }
188 190

  
189 191
log_info() { symbol=? log_custom "$@"; }
190 192

  
......
203 205

  
204 206
# usage: (stdout2log_fd; cmd...) || return
205 207
# `|| return` needed on Mac because of bug where -e doesn't apply to ()
206
stdout2log_fd() { exec >&2; }
208
stdout2log_fd() { exec >&"$log_fd"; }
207 209

  
208 210

  
209 211
### command echoing
......
293 295
	log++
294 296
	if can_log; then
295 297
		pipe_delay
296
		echo ----- >&2
297
		tee -a /dev/stderr;
298
		echo ----- >&2
298
		echo ----- >&"$log_fd"
299
		tee -a /dev/fd/"$log_fd";
300
		echo ----- >&"$log_fd"
299 301
	else cat
300 302
	fi
301 303
}

Also available in: Unified diff