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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user