Skip to main content
Glama
logging_config.py1.62 kB
"""Logging configuration for yt-fetch with Rich formatting.""" import logging from typing import Optional from rich.console import Console from rich.logging import RichHandler from rich.traceback import install def setup_logging(level: str = "INFO", log_file: Optional[str] = None) -> None: """Configure Rich logging for the application.""" # Install rich traceback handler for better error formatting install(show_locals=True) log_level = getattr(logging, level.upper(), logging.INFO) # Create rich console for stderr console = Console(stderr=True, force_terminal=True) # Rich handler for console output rich_handler = RichHandler( console=console, rich_tracebacks=True, markup=True, show_time=True, show_level=True, show_path=True, ) rich_handler.setLevel(log_level) # Root logger configuration root_logger = logging.getLogger() root_logger.setLevel(log_level) root_logger.addHandler(rich_handler) # File handler if specified (plain text for files) if log_file: file_formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) file_handler = logging.FileHandler(log_file) file_handler.setLevel(log_level) file_handler.setFormatter(file_formatter) root_logger.addHandler(file_handler) # Suppress verbose third-party logging logging.getLogger("googleapiclient").setLevel(logging.WARNING) logging.getLogger("urllib3").setLevel(logging.WARNING) logging.getLogger("httpx").setLevel(logging.WARNING)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smith-nathanh/yt-fetch'

If you have feedback or need assistance with the MCP directory API, please join our Discord server