Skip to main content
Glama
serverlogging.py1.73 kB
import logging import os def init_logging(): """ Initialize logging using config-driven log path and level. All setup actions and errors are printed to console. """ # Always log serverlogging messages to console to avoid chicken-and-egg print("Initializing logging...") # Import here to avoid circular dependency issues from utils.config import get_config log_path = get_config("logging.logfile") log_level_str = get_config("logging.loglevel") if not log_level_str: print("ERROR: logging.loglevel missing in config!", flush=True) raise ValueError("logging.loglevel missing in config") try: log_level = getattr(logging, log_level_str.upper()) except AttributeError: print(f"ERROR: Invalid loglevel '{log_level_str}' in config!", flush=True) raise # Ensure log directory exists log_dir = os.path.dirname(log_path) if log_dir and not os.path.exists(log_dir): os.makedirs(log_dir, exist_ok=True) # Set up logging logger = logging.getLogger() logger.handlers.clear() logger.setLevel(log_level) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') file_handler = logging.FileHandler(log_path, encoding='utf-8') file_handler.setLevel(log_level) file_handler.setFormatter(formatter) console_handler = logging.StreamHandler() console_handler.setLevel(log_level) console_handler.setFormatter(formatter) logger.addHandler(file_handler) logger.addHandler(console_handler) print(f"Logging initialized. Log file: {log_path}, Level: {log_level_str}", flush=True) logging.info("serverlogging init complete.") def log_info(msg): logging.info(msg) def log_warning(msg): logging.warning(msg) def log_error(msg): logging.error(msg) def log_debug(msg): logging.debug(msg)

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/ElSrJuez/tinydb-emcipi'

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