Skip to content

Commit

Permalink
fix: fix multithread logging (#101)
Browse files Browse the repository at this point in the history
Signed-off-by: ReRubis <[email protected]>
  • Loading branch information
ReRubis authored Jul 8, 2024
1 parent 31e6d1e commit f4cb7f2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions asyncord/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import logging
from collections.abc import MutableMapping
from logging.handlers import QueueHandler, QueueListener
from queue import Queue
from typing import Any

import pydantic
Expand All @@ -14,14 +16,20 @@ def setup_logging(name: str) -> None:
Args:
name: Name of the logger.
"""
base_logger = logging.getLogger(name)
base_logger.addHandler(
RichHandler(
rich_tracebacks=True,
keywords=[],
tracebacks_suppress=[pydantic],
),
log_queue = Queue()
queue_handler = QueueHandler(log_queue)

rich_handler = RichHandler(
rich_tracebacks=True,
keywords=[],
tracebacks_suppress=[pydantic],
)

listener = QueueListener(log_queue, rich_handler)
listener.start()
base_logger = logging.getLogger(name)

base_logger.addHandler(queue_handler)
base_logger.setLevel(logging.INFO)


Expand Down

0 comments on commit f4cb7f2

Please sign in to comment.