Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add an optional JSON log format shared with uvicorn

オープン
#201 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
58/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
fastapi, python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Python
スター
22
フォーク
29
平均マージ
22時間 1分
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pesu-dev/auth のほかの issue

pesu-dev/auth の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。