feat: add detailed logging for module loading and context providers
Add INFO-level logging to help diagnose module loading issues: - discovery.py: Log summary of discovered modules by tier (core/optional/internal) - service.py: Log which modules are enabled for each platform (DEBUG level) - page_context.py: Log context building with platform info and which modules contributed context with key counts Example log output: [MODULES] Auto-discovered 18 modules: 5 core, 11 optional, 2 internal [CONTEXT] Building PLATFORM context for platform 'main' with 5 enabled modules [CONTEXT] Context providers called: cms(3 keys), billing(3 keys) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,13 +93,24 @@ def get_context_for_frontend(
|
||||
# Determine which modules are enabled for this platform
|
||||
if platform:
|
||||
enabled_module_codes = module_service.get_enabled_module_codes(db, platform.id)
|
||||
logger.info(
|
||||
f"[CONTEXT] Building {frontend_type.value} context for platform "
|
||||
f"'{platform.code}' with {len(enabled_module_codes)} enabled modules"
|
||||
)
|
||||
else:
|
||||
# No platform context - only core modules
|
||||
enabled_module_codes = {
|
||||
code for code, module in MODULES.items() if module.is_core
|
||||
}
|
||||
logger.info(
|
||||
f"[CONTEXT] Building {frontend_type.value} context (no platform) with "
|
||||
f"{len(enabled_module_codes)} core modules: {sorted(enabled_module_codes)}"
|
||||
)
|
||||
|
||||
# Collect context from enabled modules that have providers for this frontend
|
||||
modules_with_providers = []
|
||||
modules_contributed = []
|
||||
|
||||
for code in enabled_module_codes:
|
||||
module = MODULES.get(code)
|
||||
if module is None:
|
||||
@@ -108,15 +119,17 @@ def get_context_for_frontend(
|
||||
if not module.has_context_provider(frontend_type):
|
||||
continue
|
||||
|
||||
modules_with_providers.append(code)
|
||||
|
||||
try:
|
||||
contribution = module.get_context_contribution(
|
||||
frontend_type, request, db, platform
|
||||
)
|
||||
if contribution:
|
||||
context.update(contribution)
|
||||
modules_contributed.append(f"{code}({len(contribution)} keys)")
|
||||
logger.debug(
|
||||
f"[CONTEXT] Module '{code}' contributed {len(contribution)} keys "
|
||||
f"for {frontend_type.value}"
|
||||
f"[CONTEXT] Module '{code}' contributed: {list(contribution.keys())}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
@@ -124,6 +137,15 @@ def get_context_for_frontend(
|
||||
f"{frontend_type.value}: {e}"
|
||||
)
|
||||
|
||||
if modules_contributed:
|
||||
logger.info(
|
||||
f"[CONTEXT] Context providers called: {', '.join(modules_contributed)}"
|
||||
)
|
||||
elif modules_with_providers:
|
||||
logger.info(
|
||||
f"[CONTEXT] {len(modules_with_providers)} modules have providers but none contributed"
|
||||
)
|
||||
|
||||
# Add any extra context passed by the caller
|
||||
if extra_context:
|
||||
context.update(extra_context)
|
||||
|
||||
@@ -109,7 +109,17 @@ def discover_modules() -> dict[str, "ModuleDefinition"]:
|
||||
except Exception as e:
|
||||
logger.error(f"Error discovering module in {module_dir}: {e}")
|
||||
|
||||
logger.info(f"Auto-discovered {len(modules)} modules")
|
||||
# Log summary by tier
|
||||
core = [c for c, m in modules.items() if m.is_core]
|
||||
internal = [c for c, m in modules.items() if m.is_internal]
|
||||
optional = [c for c, m in modules.items() if not m.is_core and not m.is_internal]
|
||||
|
||||
logger.info(
|
||||
f"[MODULES] Auto-discovered {len(modules)} modules: "
|
||||
f"{len(core)} core ({', '.join(sorted(core))}), "
|
||||
f"{len(optional)} optional ({', '.join(sorted(optional))}), "
|
||||
f"{len(internal)} internal ({', '.join(sorted(internal))})"
|
||||
)
|
||||
return modules
|
||||
|
||||
|
||||
|
||||
@@ -182,6 +182,11 @@ class ModuleService:
|
||||
# Resolve dependencies - add required modules
|
||||
enabled_set = self._resolve_dependencies(enabled_set)
|
||||
|
||||
logger.debug(
|
||||
f"[MODULES] Platform '{platform.code}' (id={platform_id}) has "
|
||||
f"{len(enabled_set)} modules enabled: {sorted(enabled_set)}"
|
||||
)
|
||||
|
||||
return enabled_set
|
||||
|
||||
def _migrate_json_to_junction_table(
|
||||
|
||||
Reference in New Issue
Block a user