Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add an optional JSON log format shared with uvicorn

Aperta
#201 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
fastapi, python

Direzione di ricerca

Read CONTRIBUTING.md, then inspect main() in app/app.py and the existing test_main_function_* tests in tests/unit/test_app_unit.py. Trace how uvicorn.run is configured and how logging is currently initialized before defining the shared configuration. Done means both app and uvicorn logs support the documented JSON/text modes, tests cover the listed fields and safety requirements, and README plus .env.example are updated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

api enhancement

🔄 Updated for v5.0.0 (2026-10-08). Still open. #208 has since removed the stray filemode argument, so the background no longer mentions it. 5.0.0 (#241) logs the whole profile at INFO, now including gender and dateOfBirth; that is deliberate, and this issue changes only the format.

Summary

pesu-auth writes plain-text logs, and uvicorn's own logs (access log, startup, errors) use a different format. Plain text is fine on a laptop, but hard to search and filter in a log service: finding "all failed logins for this user in the last hour" means writing regular expressions. Add an optional structured JSON log format, used by both pesu-auth and uvicorn, while keeping today's readable text as the default for local development.

Background

  • main() in app/app.py calls logging.basicConfig(level=..., format=...).
  • uvicorn.run(...) is called without log_config, so uvicorn installs its own default logging config for uvicorn, uvicorn.error and uvicorn.access.
  • Usernames and profile data are logged at INFO on purpose, to trace logins (see docs/security.md). This issue changes how logs are formatted, not what is logged. Passwords and tokens must never appear.

Proposed change

  1. Setting: a LOG_FORMAT environment variable, text (the default) or json, read once at startup. An unknown value fails startup with a clear message. Document it in .env.example and the README.
  2. JSON formatter, using only the standard library (a small logging.Formatter subclass in app/logging_config.py), so no new dependency is needed. One JSON object per line, with:
    • timestamp (ISO 8601 with offset), level, logger, message;
    • module, function, line;
    • exc_info as a string when present;
    • request_id when #200 is in.
  3. One configuration for everything: build a logging.config.dictConfig-style dict used both by the app and as uvicorn.run(..., log_config=...), so uvicorn's access and error logs use the same format. Keep --debug controlling the level.
  4. A maintainer sets LOG_FORMAT=json on the Render services after merge. Mention this in the PR description.

Tests

  • The JSON formatter: valid JSON on one line; includes the fields above; exceptions are serialised; non-ASCII usernames are handled.
  • main() passes the same config to uvicorn (patch uvicorn.run, as the existing test_main_function_* tests in tests/unit/test_app_unit.py do).
  • LOG_FORMAT accepts text and json, and anything else is rejected.
  • No test output contains a password.

Acceptance criteria

  • LOG_FORMAT=json makes every log line, the app's and uvicorn's, a single JSON object
  • The default output is readable text, as today
  • No new dependency; documented in the README and .env.example

How to contribute

  • Wait until you're assigned. Comment to ask for this issue, then wait for a maintainer to assign it to you before writing any code. PRs for unassigned issues are closed without review.
  • Read CONTRIBUTING.md first. It covers forking, setting up with uv, and running the tests.
  • Branch from dev in your fork, and open the PR against dev with a Conventional Commit title and Closes #201 in the description.
  • Bump the minor version in pyproject.toml and run uv lock (CI checks this). uv run pre-commit run --all-files must pass, and coverage must stay at 100%.
  • Update the README, app/docs/ and comments in the same PR as the behaviour they describe.
  • Never log, print, store or echo a password or token, including in tests, PR descriptions and screenshots.
Lingua principale
Python
Stelle
22
Fork
29
Merge medio
22h 1m
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pesu-dev/auth

Tutte le issue di pesu-dev/auth

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.