Allow debug output to be logged to a file (set $debugFile to target pathname)

or both stdout and a file (precede $debugFile pathname with a plus-sign, `+').
This commit is contained in:
Devin Teske 2012-12-28 23:49:17 +00:00
parent 39ce5cceae
commit 9c83db2d4c

View File

@ -72,7 +72,12 @@ f_dprintf()
{ {
[ "$debug" ] || return $SUCCESS [ "$debug" ] || return $SUCCESS
local fmt="$1"; shift local fmt="$1"; shift
case "$debugFile" in ""|+*)
printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1} printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1}
esac
[ "${debugFile#+}" ] &&
printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}"
return $SUCCESS
} }
# f_err $fmt [ $opts ... ] # f_err $fmt [ $opts ... ]
@ -516,6 +521,25 @@ eval exec $TERMINAL_STDERR_PASSTHRU\>\&2
# #
[ "$debug" ] && export debug [ "$debug" ] && export debug
#
# Truncate the debug file upon initialization (now). Note that we will trim a
# leading plus (`+') from the value of debugFile to support persistant meaning
# that f_dprintf() should print both to standard output and $debugFile (minus
# the leading plus, of course).
#
_debug_file="${debugFile#+}"
if [ "$_debug_file" ]; then
if ( umask 022 && :> "$_debug_file" ); then
f_dprintf "Successfully initialized debugFile \`%s'" \
"$_debug_file"
else
unset debugFile
f_dprintf "Unable to initialize debugFile \`%s'" \
"$_debug_file"
fi
fi
unset _debug_file
# #
# Log our operating environment for debugging purposes # Log our operating environment for debugging purposes
# #