T13.4 follow-up: make the sync's log lines visible under gunicorn (D18)

Nothing configures Python logging and gunicorn only configures its own loggers,
so INFO lines from wpsuite.* were dropped: with the production launch command a
healthy start printed no Okta lines, and an operator could not tell the sync was
off from on-and-quiet. okta_sync's logger now has its own stderr handler, only
when the root logger has none. Verified with real gunicorn, 2 workers, with and
without a token. Other modules' output is unchanged.
This commit is contained in:
2026-10-16 13:30:47 -07:00
parent bbfa403117
commit 2abd55c745
2 changed files with 37 additions and 0 deletions

View File

@@ -242,6 +242,17 @@ network change. The host firewall must allow https to the Okta org.
total (`TOTAL_DEADLINE_SECONDS`), which is what lets the scheduler promise no
overlap. Tested in `tests/okta_sync_check.py` section 8.
**T13.4 follow-up, 2026-10-16:** the sync's INFO log lines did not appear in
`docker compose logs api`. Nothing in the app configures Python logging, and
gunicorn configures only its own loggers, so INFO from any `wpsuite.*` logger is
dropped. The T13.4 check booted the app in-process with logging switched on,
which hid it. With the exact Dockerfile launch (2 gunicorn workers), a healthy
start printed zero Okta lines. `okta_sync.py` now gives its own logger one stderr
handler (only when the root logger has none). Re-run with the real gunicorn
command: `configured` and `scheduled` (or `DISABLED`) now print once per worker.
No other module's output changed. App-wide logging stays a separate question
(BL-028 is the same family).
### T13.5 — D18: admin visibility
- **Items:** `D18`

View File

@@ -54,6 +54,32 @@ from . import models, okta_auth
log = logging.getLogger("wpsuite.okta_sync")
def _make_logs_visible() -> None:
"""Make this module's INFO lines reach `docker compose logs api`.
Nothing in this app configures Python logging, and gunicorn only configures its
own loggers. So the root logger sits at WARNING with no handler, and every
INFO line from a `wpsuite.*` logger is dropped. Found on 2026-10-16: with the
exact production launch command, `grep "Okta sync"` found nothing on a healthy
start, because "configured", "scheduled" and "done" are INFO lines. Warnings
and errors (a disable, a skipped run) showed, but the lines that say the sync
is alive did not. An operator cannot tell "off" from "on and quiet".
This adds one stderr handler to THIS module's logger only, and only when the
root logger has none, so it never doubles up if logging is configured later and
it does not change what any other module prints. (BL-028 and the general
question of app-wide logging are separate items.)"""
if log.handlers or logging.getLogger().handlers:
return
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s"))
log.addHandler(handler)
log.setLevel(logging.INFO)
_make_logs_visible()
# Okta's own page maximum for this endpoint. Asking for the maximum keeps a
# 20-odd account org to a single call.
PAGE_LIMIT = 200