-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: run log writer in a separate thread
- Loading branch information
Showing
8 changed files
with
73 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import logging.handlers | ||
import queue | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
from rich.console import Console | ||
|
||
|
||
def configure() -> tuple[Console, logging.handlers.QueueListener]: | ||
log_queue: queue.Queue[Any] = queue.Queue() | ||
|
||
logging.root.setLevel(logging.INFO) | ||
logging.root.addHandler(logging.handlers.QueueHandler(log_queue)) | ||
|
||
# Start logging before importing rich for the first time | ||
from rich.console import Console # noqa: PLC0415 | ||
from rich.logging import RichHandler # noqa: PLC0415 | ||
|
||
console = Console() | ||
stream_handler = RichHandler( | ||
console=console, | ||
omit_repeated_times=False, | ||
show_path=False, | ||
log_time_format=logging.Formatter.default_time_format, | ||
) | ||
|
||
return console, logging.handlers.QueueListener(log_queue, stream_handler) |
This file contains 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
This file contains 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
This file contains 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