Skip to content

Honor debug level for file logging#99

Merged
Ahmed-Hindy merged 2 commits into
mainfrom
dev/issue-97-file-log-debug
Jun 12, 2026
Merged

Honor debug level for file logging#99
Ahmed-Hindy merged 2 commits into
mainfrom
dev/issue-97-file-log-debug

Conversation

@Ahmed-Hindy

@Ahmed-Hindy Ahmed-Hindy commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • make the rotating file log honor the resolved RenderKit log level instead of forcing INFO
  • keep existing file handlers in sync when setup_logging() is called again with a different level
  • add regression coverage for env-driven, explicit, and reconfigured DEBUG file logging
  • isolate RenderKit-owned root logging handlers between tests so captured streams do not leak across the suite

Root Cause

setup_logging() applied RENDERKIT_LOG_LEVEL to the RenderKit logger and console/UI handlers, but the rotating file handler was hard-coded to INFO. That meant DEBUG records were filtered out of the durable file log even when the logger accepted them.

Validation

  • uv --native-tls run --extra dev pytest tests/test_logging_utils.py
  • uv --native-tls run --extra dev pytest
  • uv --native-tls run --extra dev ruff check src\renderkit\logging_utils.py tests\test_logging_utils.py tests\conftest.py
  • uv --native-tls run --extra dev ruff format --check src\renderkit\logging_utils.py tests\test_logging_utils.py tests\conftest.py

Closes #97

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced file logging handler management to properly update log levels when reconfiguring logging multiple times.
  • Tests

    • Added comprehensive test coverage for logging configuration behavior with environment variables and explicit log level settings, ensuring reliable cross-test isolation.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Ahmed-Hindy, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 48 minutes and 55 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 97afe90c-6473-4899-b869-49f7d05bff5b

📥 Commits

Reviewing files that changed from the base of the PR and between 0cc24be and 294cc96.

📒 Files selected for processing (2)
  • tests/conftest.py
  • tests/test_logging_utils.py
📝 Walkthrough

Walkthrough

Fixed a bug where RENDERKIT_LOG_LEVEL=DEBUG was ignored by the file log handler. Refactored file handler management to update its level on every setup_logging() call, added test infrastructure to prevent handler cross-contamination, and added three test cases covering environment-variable, explicit-parameter, and reconfiguration scenarios.

Changes

File Log Level Handler Fix

Layer / File(s) Summary
File handler helper and level management
src/renderkit/logging_utils.py
New _get_handler() helper retrieves an existing handler by custom attribute. setup_logging() now fetches existing file handlers, creates them only if missing, and unconditionally sets the computed log level on both new and existing handlers (previously hard-coded to INFO).
Test fixture for logging handler cleanup
tests/conftest.py
Autouse fixture with _close_renderkit_logging_handlers() helper removes and closes RenderKit-tagged handlers before and after each test to prevent state leakage.
File log level test cases
tests/test_logging_utils.py
New test module with helper functions and three tests: env-var debug level reaches file log, explicit level parameter overrides env, and reconfiguring setup_logging() updates handler level for subsequent logs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 A logger once stuck at INFO's low gate,
Could not catch the DEBUG that came just too late,
Now handlers remember their flexible way,
And trace all the secrets you need to display!
With tests keeping watch, no more leaks in the dawn. 🌙✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Honor debug level for file logging' accurately and directly summarizes the main change: making the file handler respect the configured debug level instead of hard-coding it to INFO.
Linked Issues check ✅ Passed All coding requirements from #97 are met: file handler now respects RENDERKIT_LOG_LEVEL (direct level configuration added), tests verify DEBUG level works via environment and explicit parameters, and reconfiguration updates existing handlers.
Out of Scope Changes check ✅ Passed All changes align with fixing the file logging level issue and its tests; no unrelated modifications detected in the logging implementation or test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/issue-97-file-log-debug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ahmed-Hindy Ahmed-Hindy self-assigned this Jun 12, 2026
@Ahmed-Hindy Ahmed-Hindy marked this pull request as ready for review June 12, 2026 09:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_logging_utils.py (1)

25-42: 💤 Low value

Redundant cleanup in test_env_debug_level_reaches_file_log, test_explicit_debug_level_reaches_file_log, and test_reconfigured_debug_level_updates_existing_file_handler.

All three test functions call _remove_renderkit_handlers() at the start and in a finally block for cleanup. This is redundant because the autouse fixture cleanup_renderkit_logging_handlers in tests/conftest.py (lines 18-23) already removes and closes RenderKit handlers before and after each test. The shared root cause is defensive cleanup that duplicates the fixture's responsibility. Consider removing the explicit cleanup calls from all three tests and relying on the autouse fixture for test isolation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_logging_utils.py` around lines 25 - 42, Remove the redundant
manual cleanup calls to _remove_renderkit_handlers() in the three tests
test_env_debug_level_reaches_file_log,
test_explicit_debug_level_reaches_file_log, and
test_reconfigured_debug_level_updates_existing_file_handler; rely on the autouse
fixture cleanup_renderkit_logging_handlers in tests/conftest.py to perform
pre-/post-test handler removal and closing instead of calling
_remove_renderkit_handlers() at the start and in the finally block of these
tests, leaving the rest of each test intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_logging_utils.py`:
- Around line 11-16: The function _remove_renderkit_handlers duplicates
_close_renderkit_logging_handlers from conftest; remove the duplicate helper
from tests/test_logging_utils.py and either import and reuse
_close_renderkit_logging_handlers (replace any calls to
_remove_renderkit_handlers with _close_renderkit_logging_handlers) or delete all
explicit calls and rely on the autouse fixture in conftest to perform the
cleanup; ensure no remaining references to _remove_renderkit_handlers remain and
run tests to confirm no regressions.

---

Nitpick comments:
In `@tests/test_logging_utils.py`:
- Around line 25-42: Remove the redundant manual cleanup calls to
_remove_renderkit_handlers() in the three tests
test_env_debug_level_reaches_file_log,
test_explicit_debug_level_reaches_file_log, and
test_reconfigured_debug_level_updates_existing_file_handler; rely on the autouse
fixture cleanup_renderkit_logging_handlers in tests/conftest.py to perform
pre-/post-test handler removal and closing instead of calling
_remove_renderkit_handlers() at the start and in the finally block of these
tests, leaving the rest of each test intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 47ca61bd-b658-464b-8b4d-bf5ee6950b46

📥 Commits

Reviewing files that changed from the base of the PR and between 0a66271 and 0cc24be.

📒 Files selected for processing (3)
  • src/renderkit/logging_utils.py
  • tests/conftest.py
  • tests/test_logging_utils.py

Comment thread tests/test_logging_utils.py Outdated
@sonarqubecloud

Copy link
Copy Markdown

@Ahmed-Hindy Ahmed-Hindy merged commit e833601 into main Jun 12, 2026
8 checks passed
@Ahmed-Hindy Ahmed-Hindy deleted the dev/issue-97-file-log-debug branch June 12, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: RENDERKIT_LOG_LEVEL=DEBUG is ignored by the file log

2 participants