mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-01 16:04:24 -08:00
- Remove array_status, system_info, notifications_overview, and parity_status resources - Keep only logs_stream resource (unraid://logs/stream) which is working properly - Update README.md with current resource documentation and modern docker compose syntax - Fix import path issues that were causing subscription errors - Update environment configuration examples - Clean up subscription manager to only include working log streaming 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
"""Logging configuration for Unraid MCP Server.
|
|
|
|
This module sets up structured logging with console and rotating file handlers
|
|
that can be used consistently across all modules.
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
from .settings import LOG_LEVEL_STR, LOG_FILE_PATH
|
|
|
|
|
|
def setup_logger(name: str = "UnraidMCPServer") -> logging.Logger:
|
|
"""Set up and configure the logger with console and file handlers.
|
|
|
|
Args:
|
|
name: Logger name (defaults to UnraidMCPServer)
|
|
|
|
Returns:
|
|
Configured logger instance
|
|
"""
|
|
# Get numeric log level
|
|
numeric_log_level = getattr(logging, LOG_LEVEL_STR, logging.INFO)
|
|
|
|
# Define the logger
|
|
logger = logging.getLogger(name)
|
|
logger.setLevel(numeric_log_level)
|
|
logger.propagate = False # Prevent root logger from duplicating handlers
|
|
|
|
# Clear any existing handlers
|
|
logger.handlers.clear()
|
|
|
|
# Console Handler
|
|
console_handler = logging.StreamHandler(sys.stdout)
|
|
console_handler.setLevel(numeric_log_level)
|
|
console_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
console_handler.setFormatter(console_formatter)
|
|
logger.addHandler(console_handler)
|
|
|
|
# File Handler with Rotation
|
|
# Rotate logs at 5MB, keep 3 backup logs
|
|
file_handler = RotatingFileHandler(
|
|
LOG_FILE_PATH,
|
|
maxBytes=5*1024*1024,
|
|
backupCount=3,
|
|
encoding='utf-8'
|
|
)
|
|
file_handler.setLevel(numeric_log_level)
|
|
file_formatter = logging.Formatter(
|
|
'%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(funcName)s - %(lineno)d - %(message)s'
|
|
)
|
|
file_handler.setFormatter(file_formatter)
|
|
logger.addHandler(file_handler)
|
|
|
|
return logger
|
|
|
|
|
|
def log_configuration_status(logger: logging.Logger) -> None:
|
|
"""Log configuration status at startup.
|
|
|
|
Args:
|
|
logger: Logger instance to use for logging
|
|
"""
|
|
from .settings import get_config_summary
|
|
|
|
logger.info(f"Logging initialized (console and file: {LOG_FILE_PATH}).")
|
|
|
|
config = get_config_summary()
|
|
|
|
# Log configuration status
|
|
if config['api_url_configured']:
|
|
logger.info(f"UNRAID_API_URL loaded: {config['api_url_preview']}")
|
|
else:
|
|
logger.warning("UNRAID_API_URL not found in environment or .env file.")
|
|
|
|
if config['api_key_configured']:
|
|
logger.info("UNRAID_API_KEY loaded: ****") # Don't log the key itself
|
|
else:
|
|
logger.warning("UNRAID_API_KEY not found in environment or .env file.")
|
|
|
|
logger.info(f"UNRAID_MCP_PORT set to: {config['server_port']}")
|
|
logger.info(f"UNRAID_MCP_HOST set to: {config['server_host']}")
|
|
logger.info(f"UNRAID_MCP_TRANSPORT set to: {config['transport']}")
|
|
logger.info(f"UNRAID_MCP_LOG_LEVEL set to: {config['log_level']}")
|
|
|
|
if not config['config_valid']:
|
|
logger.error(f"Missing required configuration: {config['missing_config']}")
|
|
|
|
|
|
# Global logger instance - modules can import this directly
|
|
logger = setup_logger() |