25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

26 satır
690 B

  1. import logging
  2. from typing import Union
  3. from rich.console import Console
  4. from rich.logging import RichHandler
  5. def setup_logging(
  6. terminal_width: Union[int, None] = None, level: int = logging.INFO
  7. ) -> None:
  8. logger = logging.getLogger("fastapi_cli")
  9. console = Console(width=terminal_width) if terminal_width else None
  10. rich_handler = RichHandler(
  11. show_time=False,
  12. rich_tracebacks=True,
  13. tracebacks_show_locals=True,
  14. markup=True,
  15. show_path=False,
  16. console=console,
  17. )
  18. rich_handler.setFormatter(logging.Formatter("%(message)s"))
  19. logger.addHandler(rich_handler)
  20. logger.setLevel(level)
  21. logger.propagate = False