Skip to content

refactor: optimize logging performance and modernize string formatting - #2

Open
ahoblitz wants to merge 15 commits into
mainfrom
fix/logging-and-string-formatting
Open

ahoblitz wants to merge 15 commits into
mainfrom
fix/logging-and-string-formatting

Conversation

@ahoblitz

Copy link
Copy Markdown
Owner

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Changes

This PR optimizes logging performance and modernizes string formatting throughout the codebase.

Logging Performance Optimization

  • Replaced f-string formatting in logging calls with % formatting for lazy evaluation
  • This prevents unnecessary string formatting when log levels are disabled (e.g., DEBUG in production)
  • Updated 12 logging instances across 6 files

String Formatting Modernization

  • Converted .format() calls to f-strings in server/models.py for better readability
  • Updated 4 __repr__ methods

Additional Improvements

  • Added test_venv/ to .gitignore to prevent virtual environments from being committed

Performance Impact

Using % formatting in logging provides significant performance benefits:

# Before (always evaluates)
logger.debug(f'Task {task_id} saved')

# After (only evaluates if DEBUG is enabled)  
logger.debug('Task %s saved', task_id)

In production with DEBUG disabled, this avoids unnecessary string operations and object conversions.

Fixes NA

@ahoblitz
ahoblitz force-pushed the fix/logging-and-string-formatting branch 2 times, most recently from 188c146 to 74961ab Compare August 16, 2025 13:49
- Replace f-strings with % formatting in logging calls for lazy evaluation
- Convert .format() to f-strings in server/models.py __repr__ methods
- Add test_venv/ to .gitignore
- Use logger.exception() for better error debugging with full tracebacks
- Improves performance by avoiding string formatting when log levels are disabled

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ahoblitz
ahoblitz force-pushed the fix/logging-and-string-formatting branch from 74961ab to 62930b2 Compare August 16, 2025 13:52
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.

2 participants