Skip to content

Commit

Permalink
Improve voltage warning lines in TinyPilot logs (#1544)
Browse files Browse the repository at this point in the history
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 <command>` test
to be used.

Short arguments were used for consistency with the majority of the rest
of the `collect-debug-logs` script.
<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1544"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
cghague authored Aug 9, 2023
1 parent edcf2f8 commit f9ab492
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down

0 comments on commit f9ab492

Please sign in to comment.