Skip to content

Commit

Permalink
Copy logs to SHARED_DIR on exit (#3185)
Browse files Browse the repository at this point in the history
* Copy debug logs to SHARED_DIR on exit

* Compress log files to save space as the limit is 1MB
  • Loading branch information
mgencur authored Dec 17, 2024
1 parent f0af47c commit a2a3fdf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions hack/lib/ui.bash
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ function stacktrace {
}

function debugging.setup {
local debuglog debugdir
debugdir="${ARTIFACTS:-/tmp}"
debuglog="${debugdir}/debuglog-$(basename "$0").log"
local debuglog logdir stdoutlog stderrlog
logdir="${ARTIFACTS:-/tmp}"
debuglog="${logdir}/debuglog-$(basename "$0").log"
stdoutlog="${logdir}/stdout-$(basename "$0").log"
stderrlog="${logdir}/stderr-$(basename "$0").log"
logger.debug "Debug log (set -x) is written to: ${debuglog}"
# ref: https://serverfault.com/a/579078
# Use FD 19 to capture the debug stream caused by "set -x":
Expand All @@ -68,13 +70,21 @@ function debugging.setup {

# Register finish of debugging at exit
trap debugging.finish EXIT

# Send stdout and stderr also to log files.
# shellcheck disable=SC2093
exec 1> >(tee "${stdoutlog}" >&1) 2> >(tee "${stderrlog}" >&2)
set -x
}

function debugging.finish {
# Close the output:
set +x
exec 19>&-

if [ -n "${SHARED_DIR:-}" ] && [ -n "${JOB_NAME_SAFE:-}" ]; then
tar -czvf "${SHARED_DIR}/${JOB_NAME_SAFE}-testlog.tar.gz" "${ARTIFACTS}"/debuglog-*.log "${ARTIFACTS}"/stdout-*.log "${ARTIFACTS}"/stderr-*.log || true
fi
}

function logger.debug {
Expand Down

0 comments on commit a2a3fdf

Please sign in to comment.