logger.py•719 B
"""
Logging utilities for MCP server.
Logs to stderr to keep stdout clean for JSON-RPC communication.
"""
import sys
from datetime import datetime
def log(message, level="INFO"):
"""
Write a log message to stderr.
Args:
message: The log message
level: Log level (INFO, ERROR, DEBUG, etc.)
"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{timestamp}] [{level}] {message}", file=sys.stderr, flush=True)
def log_error(message):
"""Log an error message."""
log(message, "ERROR")
def log_debug(message):
"""Log a debug message."""
log(message, "DEBUG")
def log_info(message):
"""Log an info message."""
log(message, "INFO")