From f9ab492c34259fd02579f2fa3c7e7f3aa4f2f0e3 Mon Sep 17 00:00:00 2001 From: cghague <53837824+cghague@users.noreply.github.com> Date: Thu, 10 Aug 2023 00:58:31 +0100 Subject: [PATCH] Improve voltage warning lines in TinyPilot logs (#1544) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #1495 Parses the output of `journalctl` into a simple “yes” or “no” result. If the result is “yes”, the latest voltage warning is also included in the output. ## Parsing the output of `journalctl` I initially considered piping the output of `journalctl` into `grep` for readability, but getting the correct exit code as well as just the latest voltage warning was quite awkward with this approach. I therefore settled on using just the filtering and output options that are built into `journalctl`: - The `-q` argument is used to suppress the unwanted `journalctl` header text. - The `-r` argument causes `journalctl` to output from newest to oldest. - The `-n 1` argument causes `journalctl` to stop after outputting a single line. - The `-g "voltage"` argument limits output to only lines that contain the word “voltage”. The end result of this combination of arguments is that `journalctl` will efficiently output only the most recent voltage warning. In addition, the exit status of the command reflects whether or not any matching lines were found, which allows for a simple `if ` test to be used. Short arguments were used for consistency with the majority of the rest of the `collect-debug-logs` script. Review
on CodeApprove --- .../tinypilot-privileged/scripts/collect-debug-logs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs b/debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs index b67666201..98b132778 100755 --- a/debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs +++ b/debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs @@ -148,9 +148,13 @@ print_info "Checking throttled state..." print_info "Checking for voltage issues..." { - echo "voltage logs" - journalctl --catalog --pager-end | grep --ignore-case "voltage" - printf "\n" + printf "Voltage issues: " + if LAST_VOLTAGE_LINE="$(journalctl --quiet --reverse --lines=1 --grep='voltage')" ; then + printf "yes - %s" "${LAST_VOLTAGE_LINE}" + else + printf "no" + fi + printf "\n\n" } >> "${LOG_FILE}" print_info "Checking TinyPilot settings..."