diff --git a/src/core/config.py b/src/core/config.py index 989b59c..88b6798 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -6,6 +6,8 @@ class Settings(BaseSettings): PROJECT_NAME: str = "mAIcro" VERSION: str = "0.1.0" API_V1_STR: str = "/api/v1" + LOG_LEVEL: str = "INFO" + LOG_FORMAT: str = "%(asctime)s | %(levelname)s | %(name)s | %(message)s" ORG_NAME: str = "MicroClub" ORG_DESCRIPTION: Optional[str] = "A generic organization using mAIcro" diff --git a/src/core/llm_provider.py b/src/core/llm_provider.py index 2160d2e..e058729 100644 --- a/src/core/llm_provider.py +++ b/src/core/llm_provider.py @@ -14,7 +14,7 @@ class ConfigurationError(ValueError): """Raised when model providers are misconfigured.""" -_LOGGER = logging.getLogger(__name__) +logger = logging.getLogger(__name__) class RateLimitExceeded(Exception): @@ -103,7 +103,7 @@ def _invoke(prompt: str): try: return _invoke_with_rate_limit_retries(primary_llm, prompt) except RateLimitExceeded: - _LOGGER.warning( + logger.warning( "Primary Gemini model rate-limited after %s attempts; switching to fallback.", settings.LLM_MAX_PRIMARY_ATTEMPTS, ) diff --git a/src/core/logging_config.py b/src/core/logging_config.py new file mode 100644 index 0000000..3eba727 --- /dev/null +++ b/src/core/logging_config.py @@ -0,0 +1,14 @@ +import logging +import sys +from core.config import settings + +def setup_logging(): + """Centralized logging configuration.""" + logging.basicConfig( + level=getattr(logging, settings.LOG_LEVEL.upper(), logging.INFO), + format=settings.LOG_FORMAT, + handlers=[ + logging.StreamHandler(sys.stdout) + ], + force=True # Ensure that the root logger is reset and configured correctly + ) diff --git a/src/main.py b/src/main.py index 294c615..76b3bfa 100644 --- a/src/main.py +++ b/src/main.py @@ -11,11 +11,10 @@ from core.discord_listener import run_discord_listener from core.ingestion import ingest_from_discord, run_startup_audit import logging +from core.logging_config import setup_logging + +setup_logging() -logging.basicConfig( - level=logging.INFO, - format="%(asctime)s | %(levelname)s | %(name)s | %(message)s", -) logger = logging.getLogger(__name__)