mirror of https://github.com/Chizi123/Arch-autobuild-repo.git

Joel Grunbaum
yesterday b7cd53c75bf46cf7e7d35e36a415722bdb432b08
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Structured logging setup using Rich."""
 
import logging
from pathlib import Path
 
from rich.console import Console
from rich.logging import RichHandler
 
console = Console()
 
 
def setup_logging(
    level: str = "INFO",
    log_file: Path | None = None,
) -> logging.Logger:
    """Configure logging with Rich handler for pretty console output.
 
    Args:
        level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
        log_file: Optional path to log file
 
    Returns:
        Configured logger instance
    """
    handlers: list[logging.Handler] = [
        RichHandler(
            console=console,
            rich_tracebacks=True,
            tracebacks_show_locals=True,
            show_time=True,
            show_path=False,
        )
    ]
 
    if log_file:
        log_file.parent.mkdir(parents=True, exist_ok=True)
        file_handler = logging.FileHandler(log_file)
        file_handler.setFormatter(
            logging.Formatter("%(asctime)s | %(levelname)-8s | %(name)s | %(message)s")
        )
        handlers.append(file_handler)
 
    logging.basicConfig(
        level=getattr(logging, level.upper()),
        format="%(message)s",
        datefmt="[%X]",
        handlers=handlers,
    )
 
    return logging.getLogger("archrepobuild")
 
 
def get_logger(name: str) -> logging.Logger:
    """Get a child logger for a specific module.
 
    Args:
        name: Module name for the logger
 
    Returns:
        Logger instance
    """
    return logging.getLogger(f"archrepobuild.{name}")