-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlogging.py
More file actions
28 lines (23 loc) · 815 Bytes
/
logging.py
File metadata and controls
28 lines (23 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
import os
from rich.console import Console
from rich.logging import RichHandler
def setup_logging(terminal_width: int | None = None, level: int | None = None) -> None:
if level is None:
level = (
logging.DEBUG if os.getenv("FASTAPI_CLOUD_DEBUG") == "1" else logging.INFO
)
logger = logging.getLogger("fastapi_cloud_cli")
console = Console(width=terminal_width) if terminal_width else None
rich_handler = RichHandler(
show_time=False,
rich_tracebacks=True,
tracebacks_show_locals=True,
markup=True,
show_path=False,
console=console,
)
rich_handler.setFormatter(logging.Formatter("{message}", style="{"))
logger.addHandler(rich_handler)
logger.setLevel(level)
logger.propagate = False