Skip to content

Log the watchdog's INFO lines to the journal - #192

Merged
onyks-os merged 3 commits into
mainfrom
fix/watchdog-journal-logging
Nov 30, 2026
Merged

onyks-os merged 3 commits into
mainfrom
fix/watchdog-journal-logging

Conversation

@onyks-os

Copy link
Copy Markdown
Owner

Problem

The native packages run the watchdog as ttp-watchdog. That account cannot open root's /run/ttp/ttp.log (mode 0600). In that case setup_logging() returned before adding any handler, so Python's last-resort handler printed only WARNING and above. INFO lines appeared nowhere, neither in the file nor in the journal. One of them is the confirmation that a Tor heal succeeded. This contradicts watchdog-fsm.md, which says the result is in journalctl -u ttp-watchdog.

The first run of scripts/vm/lifecycle/heal.sh in #191 found this: it waited for the heal's INFO line, and the journal never received it.

Fix

  • If the log file cannot be opened, setup_logging() now skips only the file handler.
  • When systemd has connected stderr to the journal, and no console handler is configured, INFO and above go to stderr. Each line is prefixed with its syslog priority (<6>, <4>, …), so the journal records the level and journalctl -p warning works.
    • The check is the documented one: JOURNAL_STREAM must name stderr's device and inode. Children inherit the variable, so the variable alone is not enough.
  • A watchdog running as root keeps its file and gains the journal. --quiet keeps the journal quiet. A CLI started from a terminal behaves as before.

Tests

tests/test_logging_journal.py writes to a real file standing in for stderr:

  • INFO and ERROR reach the journal with <6> and <3>; DEBUG does not.
  • No JOURNAL_STREAM, a mismatched one, or a malformed one adds no handler.
  • With --quiet, nothing is written.
  • With the file handler present, each line goes to the journal once and to the file as well.

The two positive tests failed before the change. Full suite: 1891 passed.

Once #191 is merged, I will make heal.sh also require the heal's INFO line in the journal, so the VM job checks this end to end.

🤖 Generated with Claude Code

onyks-os and others added 3 commits November 30, 2026 11:44
The native packages run the watchdog as ttp-watchdog, which cannot open
root's /run/ttp/ttp.log (0600). setup_logging() returned early in that
case, before any console handler, so the ttp logger had no handler at
all: Python's last-resort handler printed WARNING and above, and INFO
lines appeared nowhere, a healed Tor among them. Found by the first run
of scripts/vm/lifecycle/heal.sh (#191), which waited for the heal's INFO
line in the journal and never saw it.

A file that cannot be opened now skips only the file handler. When
systemd has connected stderr to the journal (JOURNAL_STREAM names
stderr's device and inode, as the variable is inherited by children),
and no console handler is configured, INFO and above go to stderr, each
line prefixed with its syslog priority (<6>, <4>, ...), so journalctl
records the level and -p filters on it. A root watchdog keeps its file
and gains the journal; --quiet keeps the journal quiet; a CLI run from a
terminal is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
…logging

Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
#	docs/web/release-notes/changelog.md
With the journal handler, the watchdog running as ttp-watchdog logs
"Watchdog: Restarted Tor service successfully." at INFO. heal.sh now
requires that line, read with `journalctl -p info..info` so the priority
journald recorded is checked too. Before this branch the confined
watchdog logged nothing below WARNING, and this check would have failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
@onyks-os
onyks-os merged commit 5cb47f0 into main Nov 30, 2026
51 of 54 checks passed
@onyks-os
onyks-os deleted the fix/watchdog-journal-logging branch November 30, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant