Simplify logging. Allow to passing handlers to entrypoint #220
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.
Summary
This PR introduces significant improvements to the logging system while also applying several style reformatting changes (referred to as “reformat with gray”) across the codebase.
Major Changes: Logging System Enhancements
New
ThreadedHandler
:Deprecation of Legacy MemoryHandler Approach:
logging.handlers.MemoryHandler
and a background flusher) is replaced.wrap_logging_handler
now issues a deprecation warning and returns an instance of the newThreadedHandler
.Updated Logging Configuration in
basic_config
:ThreadedHandler
, ensuring:Additional Logging Adjustments:
UnhandledLoopHook
for better trace formatting.ThreadedHandler
in the public API to allow custom usage if needed.Other Changes: Reformat with Gray
Function Signatures and Imports:
aggregate.py
,backoff.py
,entrypoint.py
,uvicorn.py
, andtimeout.py
).Minor Code Cleanups:
Motivation
Enhanced Asynchronous Logging:
By offloading logging to a separate thread, the new system minimizes the risk of blocking the asyncio event loop, especially under high load.
Improved Code Consistency:
The reformatting changes (reformat with gray) make the codebase cleaner and more maintainable without altering any business logic.
Impact
wrap_logging_handler
.Migration
For Users:
Documentation:
ThreadedHandler
.Feedback and suggestions are welcome. This refactor sets a robust foundation for asynchronous logging while ensuring the code remains clean and consistent through the reformatting updates.