Skip to content

feat(Logging): Unify logging format#7050

Merged
khvn26 merged 4 commits intomainfrom
feat/logging-improvements
Mar 30, 2026
Merged

feat(Logging): Unify logging format#7050
khvn26 merged 4 commits intomainfrom
feat/logging-improvements

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Mar 26, 2026

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to Flagsmith/flagsmith-common#31

Migrates logging setup from Django settings to flagsmith-common's setup_logging(), which runs before Django loads.

  • Set LOGGING_CONFIG = None to prevent Django from wiping setup_logging() configuration
  • Remove structlog.configure block (handled by flagsmith-common)
  • Remove unused util/logging.py
  • Remove GUNICORN_LOGGER_CLASS from .env-ci as it's no longer needed
  • Remove PROMETHEUS_HISTOGRAM_BUCKETS setting (uses library defaults)
  • Pin flagsmith-common to >=3.5.0,<4

How did you test this code?

Generic format (LOG_FORMAT=generic)

Boot logs:

2026-03-30T19:24:08.753066Z [info     ] Starting gunicorn 23.0.0       [gunicorn.error]
2026-03-30T19:24:08.753634Z [info     ] Listening at: http://0.0.0.0:8000 (11586) [gunicorn.error]
2026-03-30T19:24:08.753736Z [info     ] Using worker: sync             [gunicorn.error]
2026-03-30T19:24:08.756534Z [info     ] Prometheus metrics server started on port 9100 [common.gunicorn.metrics_server]
2026-03-30T19:24:08.761333Z [info     ] Booting worker with pid: 11674 [gunicorn.error]

Access log:

127.0.0.1 - - [30/Mar/2026:19:22:57 +0000] "GET /health/liveness/ HTTP/1.1" 200 16 "-" "curl/8.7.1" - -

Error log:

2026-03-30T19:24:12.236982Z [error    ] Invalid HTTP_HOST header: 'invalid.example.com'. You may need to add 'invalid.example.com' to ALLOWED_HOSTS. [django.security.DisallowedHost] request=<WSGIRequest: GET '/health/liveness/'> status_code=400
Traceback (most recent call last):
  ...
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'invalid.example.com'. You may need to add 'invalid.example.com' to ALLOWED_HOSTS.
  • Boot/error logs: structlog ConsoleRenderer with ISO timestamps, no ANSI in non-TTY
  • Access logs: pure CLF via Gunicorn's own handler

JSON format (LOG_FORMAT=json)

Boot logs:

{"timestamp": "2026-03-30T19:38:15.606912Z", "message": "Starting gunicorn 23.0.0", "levelname": "INFO", "logger_name": "gunicorn.error", "pid": 45196, "thread_name": "MainThread"}

Access log (structured):

{"timestamp": "2026-03-30T19:38:22.630927Z", "time": "2026-03-30T19:38:22+00:00", "path": "/health/liveness/", "remote_ip": "127.0.0.1", "method": "GET", "status": "400", "user_agent": "curl/8.7.1", "duration_in_ms": 7, "response_size_in_bytes": 143, "message": "127.0.0.1 - - [30/Mar/2026:19:38:22 +0000] \"GET /health/liveness/ HTTP/1.1\" 400 143 \"-\" \"curl/8.7.1\" - -", "levelname": "INFO", "logger_name": "gunicorn.access", "pid": 45276, "thread_name": "MainThread"}

Error log (structured):

{"timestamp": "2026-03-30T19:38:22.628454Z", "status_code": 400, "request": "<WSGIRequest: GET '/health/liveness/'>", "message": "Invalid HTTP_HOST header: 'invalid.example.com'. You may need to add 'invalid.example.com' to ALLOWED_HOSTS.", "levelname": "ERROR", "logger_name": "django.security.DisallowedHost", "pid": 45276, "thread_name": "MainThread", "exc_info": "Traceback (most recent call last):\n  File \"/Users/kgustyr/dev/flagsmith/flagsmith-common/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py\", line 55, in inner\n    response = get_response(request)\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/kgustyr/dev/flagsmith/flagsmith-common/.venv/lib/python3.12/site-packages/django/utils/deprecation.py\", line 119, in __call__\n    response = self.process_request(request)\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/Users/kgustyr/dev/flagsmith/flagsmith-common/.venv/lib/python3.12/site-packages/django/middleware/common.py\", line 48, in process_request\n    host = request.get_host()\n           ^^^^^^^^^^^^^^^^^^\n  File \"/Users/kgustyr/dev/flagsmith/flagsmith-common/.venv/lib/python3.12/site-packages/django/http/request.py\", line 202, in get_host\n    raise DisallowedHost(msg)\ndjango.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'invalid.example.com'. You may need to add 'invalid.example.com' to ALLOWED_HOSTS."}

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 30, 2026 7:45pm
flagsmith-frontend-preview Ignored Ignored Preview Mar 30, 2026 7:45pm
flagsmith-frontend-staging Ignored Ignored Preview Mar 30, 2026 7:45pm

Request Review

@github-actions github-actions bot added api Issue related to the REST API feature New feature or request labels Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (61ca107) to head (1fb1e72).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7050   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files        1337     1335    -2     
  Lines       50012    49943   -69     
=======================================
- Hits        49180    49113   -67     
+ Misses        832      830    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@khvn26 khvn26 marked this pull request as ready for review March 26, 2026 16:36
@khvn26 khvn26 requested a review from a team as a code owner March 26, 2026 16:36
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team March 26, 2026 16:36
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, reopen this pull request to trigger a review.

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7050 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-7050 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7050 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7050 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  43.6 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  10.5 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  43.7 seconds
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  da28717
info  🔄 Run: #15501 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  11.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  24.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  1 minute, 4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  56.4 seconds
commit  3d813ba
info  🔄 Run: #15502 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  42 seconds
commit  1fb1e72
info  🔄 Run: #15583 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  10 seconds
commit  1fb1e72
info  🔄 Run: #15583 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  57.7 seconds
commit  1fb1e72
info  🔄 Run: #15583 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  44.1 seconds
commit  1fb1e72
info  🔄 Run: #15583 (attempt 1)

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Mar 26, 2026
@khvn26 khvn26 changed the title feat: Migrate to flagsmith-common centralized logging feat(Logging): Migrate to flagsmith-common centralized logging Mar 30, 2026
khvn26 added 4 commits March 30, 2026 20:42
- Replace LOGGING dict with no-op (setup_logging runs before Django)
- Remove structlog.configure block (handled by flagsmith-common)
- Remove util/logging.py (JsonFormatter, GunicornJsonCapableLogger
  now in flagsmith-common)
- Remove GUNICORN_LOGGER_CLASS from .env-ci (default in flagsmith-common)
- Remove PROMETHEUS_HISTOGRAM_BUCKETS setting (uses library defaults)
- Pin flagsmith-common to feat/logging-improvements branch
…OGGERS

Use the released PyPI package instead of the git branch reference, and
set the APPLICATION_LOGGERS env var default in run-docker.sh so that
application loggers are configured at the correct level.
@khvn26 khvn26 force-pushed the feat/logging-improvements branch from fb369d8 to 1fb1e72 Compare March 30, 2026 19:45
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Mar 30, 2026
Copy link
Copy Markdown
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@khvn26 khvn26 merged commit 9f1d4ec into main Mar 30, 2026
36 checks passed
@khvn26 khvn26 deleted the feat/logging-improvements branch March 30, 2026 19:56
@khvn26 khvn26 changed the title feat(Logging): Migrate to flagsmith-common centralized logging feat(Logging): Unify logging format Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants