Unbuffer log output
* Force-flush log output so we don't lose log output in certain error cases. * Slow down exit paths: add sleep to die(), wait until last moment to kill child processes (including the awk log output filter) Change-Id: I1620fd33b89b237d9c2bb6206f3de2c81719f676
This commit is contained in:
@@ -222,6 +222,8 @@ function die() {
|
|||||||
fi
|
fi
|
||||||
backtrace 2
|
backtrace 2
|
||||||
err $line "$*"
|
err $line "$*"
|
||||||
|
# Give buffers a second to flush
|
||||||
|
sleep 1
|
||||||
exit $exitcode
|
exit $exitcode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
stack.sh
26
stack.sh
@@ -522,7 +522,7 @@ if [[ -n "$LOGFILE" ]]; then
|
|||||||
exec 3>&1
|
exec 3>&1
|
||||||
if [[ "$VERBOSE" == "True" ]]; then
|
if [[ "$VERBOSE" == "True" ]]; then
|
||||||
# Redirect stdout/stderr to tee to write the log file
|
# Redirect stdout/stderr to tee to write the log file
|
||||||
exec 1> >( awk '
|
exec 1> >( awk -v logfile=${LOGFILE} '
|
||||||
/((set \+o$)|xtrace)/ { next }
|
/((set \+o$)|xtrace)/ { next }
|
||||||
{
|
{
|
||||||
cmd ="date +\"%Y-%m-%d %H:%M:%S.%3N | \""
|
cmd ="date +\"%Y-%m-%d %H:%M:%S.%3N | \""
|
||||||
@@ -530,8 +530,9 @@ if [[ -n "$LOGFILE" ]]; then
|
|||||||
close("date +\"%Y-%m-%d %H:%M:%S.%3N | \"")
|
close("date +\"%Y-%m-%d %H:%M:%S.%3N | \"")
|
||||||
sub(/^/, now)
|
sub(/^/, now)
|
||||||
print
|
print
|
||||||
fflush()
|
print > logfile
|
||||||
}' | tee "${LOGFILE}" ) 2>&1
|
fflush("")
|
||||||
|
}' ) 2>&1
|
||||||
# Set up a second fd for output
|
# Set up a second fd for output
|
||||||
exec 6> >( tee "${SUMFILE}" )
|
exec 6> >( tee "${SUMFILE}" )
|
||||||
else
|
else
|
||||||
@@ -579,21 +580,24 @@ fi
|
|||||||
# -----------------------
|
# -----------------------
|
||||||
|
|
||||||
# Kill background processes on exit
|
# Kill background processes on exit
|
||||||
trap clean EXIT
|
trap exit_trap EXIT
|
||||||
clean() {
|
function exit_trap {
|
||||||
local r=$?
|
local r=$?
|
||||||
kill >/dev/null 2>&1 $(jobs -p)
|
echo "exit_trap called, cleaning up child processes"
|
||||||
|
kill 2>&1 $(jobs -p)
|
||||||
exit $r
|
exit $r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Exit on any errors so that errors don't compound
|
# Exit on any errors so that errors don't compound
|
||||||
trap failed ERR
|
trap err_trap ERR
|
||||||
failed() {
|
function err_trap {
|
||||||
local r=$?
|
local r=$?
|
||||||
kill >/dev/null 2>&1 $(jobs -p)
|
|
||||||
set +o xtrace
|
set +o xtrace
|
||||||
[ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
|
if [[ -n "$LOGFILE" ]]; then
|
||||||
|
echo "${0##*/} failed: full log in $LOGFILE"
|
||||||
|
else
|
||||||
|
echo "${0##*/} failed"
|
||||||
|
fi
|
||||||
exit $r
|
exit $r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user