feat(logging): add rotating file logging with AppSettings-backed level override - #155
Closed
geourjoa wants to merge 3 commits into
Closed
feat(logging): add rotating file logging with AppSettings-backed level override#155geourjoa wants to merge 3 commits into
geourjoa wants to merge 3 commits into
Conversation
…l override Adds a RotatingFileHandler alongside the existing console handler, wired into both the `django` and `apps` loggers, with the target path/dir configurable via a new LOG_FILE_PATH env var (settings.py creates the directory on boot since Django won't). Persists across container restarts via a new `app_logs` volume mounted on the `api` service in compose.yaml. The static APP_LOG_LEVEL fallback default changes from INFO to ERROR per the issue. A runtime hook in CommonConfig.ready() looks up an active AppSettings(key="LOG_LEVEL") row and, if valid, overrides the `apps`/ `django` logger levels at process start — this can't live directly in the LOGGING dict because settings.py loads before migrations are guaranteed to run (or the DB is even reachable), so it's guarded with try/except. Seeds the LOG_LEVEL AppSettings row (value "ERROR") via a standard RunPython data migration. Depends on feat-1/app-settings-model (AppSettings model), not yet merged.
…t writable os.makedirs(dirname(LOG_FILE_PATH)) ran unguarded at settings.py import time. The default /var/log/app is only writable inside the deployed container (where compose.yaml provisions the app_logs volume) — any other environment (local dev, CI, an unprivileged host) raised PermissionError before Django finished loading settings, which is how this branch ended up with zero CI runs at all rather than a failing one. Wraps the makedirs call and degrades to console-only logging when the directory can't be created, instead of taking down the whole app over an optional feature. Also points config/test.env's LOG_FILE_PATH at /tmp so CI/local test runs exercise the RotatingFileHandler path rather than always hitting the fallback.
Contributor
Author
|
Closing — recreating the PR didn't fix the missing pull_request-triggered checks either, so this was a platform/webhook issue, not branch-specific. Consolidating back on #150, which has identical content and has been manually verified green via workflow_dispatch (see PR description). |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recreated from #150 under a renamed branch — the original branch's
pull_requestwebhook never fired (verified: neither a fresh push nor a close/reopen triggered CI, whileworkflow_dispatchruns against it passed fully). Same commits, same content; #150 will be closed pointing here.Summary
Stacked on #148 (feat-1) — merge/rebase after that lands.
RotatingFileHandler(10MB × 5 backups) toLOGGINGinconfig/settings.pyalongside the existing console handler, driven by new env varLOG_FILE_PATH(default/var/log/app/app.log); addedapp_logsvolume tocompose.yamlmounted on theapiservice only (deliberately not shared withcelery, to avoid multi-process log-rotation corruption).LOG_LEVELis seeded intoAppSettings(defaultERROR, per spec) and applied at runtime viaCommonConfig.ready(), since Django settings load before the DB/migrations are guaranteed ready.os.makedirs(dirname(LOG_FILE_PATH))ran unguarded at settings.py import time —/var/log/appis only writable inside the deployed container (compose-provisioned volume), so any other environment (local dev, CI, an unprivileged host) hit aPermissionErrorbefore Django even finished loading settings. Now degrades to console-only logging when the directory can't be created, andconfig/test.envpointsLOG_FILE_PATHat/tmpso CI actually exercises the file handler instead of always falling back.Test plan
ruff check/ruff format/mypy/ architecture-boundaries cleanpytest apps/commonpassingNo new dependencies.