1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-23 11:18:54 +00:00

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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=244799

View File

@ -72,7 +72,12 @@ f_dprintf()
{
[ "$debug" ] || return $SUCCESS
local fmt="$1"; shift
case "$debugFile" in ""|+*)
printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1}
esac
[ "${debugFile#+}" ] &&
printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}"
return $SUCCESS
}
# f_err $fmt [ $opts ... ]
@ -516,6 +521,25 @@ eval exec $TERMINAL_STDERR_PASSTHRU\>\&2
#
[ "$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
#