This commit completes the migration to a fully module-driven architecture: ## Models Migration - Moved all domain models from models/database/ to their respective modules: - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc. - cms: MediaFile, VendorTheme - messaging: Email, VendorEmailSettings, VendorEmailTemplate - core: AdminMenuConfig - models/database/ now only contains Base and TimestampMixin (infrastructure) ## Schemas Migration - Moved all domain schemas from models/schema/ to their respective modules: - tenancy: company, vendor, admin, team, vendor_domain - cms: media, image, vendor_theme - messaging: email - models/schema/ now only contains base.py and auth.py (infrastructure) ## Routes Migration - Moved admin routes from app/api/v1/admin/ to modules: - menu_config.py -> core module - modules.py -> tenancy module - module_config.py -> tenancy module - app/api/v1/admin/ now only aggregates auto-discovered module routes ## Menu System - Implemented module-driven menu system with MenuDiscoveryService - Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT - Added MenuItemDefinition and MenuSectionDefinition dataclasses - Each module now defines its own menu items in definition.py - MenuService integrates with MenuDiscoveryService for template rendering ## Documentation - Updated docs/architecture/models-structure.md - Updated docs/architecture/menu-management.md - Updated architecture validation rules for new exceptions ## Architecture Validation - Updated MOD-019 rule to allow base.py in models/schema/ - Created core module exceptions.py and schemas/ directory - All validation errors resolved (only warnings remain) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
136 lines
4.1 KiB
Python
136 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test the hybrid logging system comprehensively.
|
|
|
|
Tests:
|
|
1. Log settings API
|
|
2. Database logging
|
|
3. File logging
|
|
4. Log viewer API
|
|
5. Log rotation
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
|
|
def test_logging_endpoints():
|
|
"""Test logging-related API endpoints."""
|
|
print("\n" + "=" * 70)
|
|
print("TESTING LOGGING SYSTEM")
|
|
print("=" * 70)
|
|
|
|
# Test 1: Create test logs at different levels
|
|
print("\n[1] Creating test logs...")
|
|
try:
|
|
logging.info("Test INFO log from test script")
|
|
logging.warning("Test WARNING log - should be in database")
|
|
logging.error("Test ERROR log - should be in database")
|
|
|
|
# Create an exception log
|
|
try:
|
|
raise ValueError("Test exception for logging")
|
|
except Exception:
|
|
logging.error("Test exception logging", exc_info=True)
|
|
|
|
print(" ✓ Test logs created")
|
|
except Exception as e:
|
|
print(f" ✗ Failed to create logs: {e}")
|
|
return False
|
|
|
|
# Test 2: Verify log files exist
|
|
print("\n[2] Checking log files...")
|
|
try:
|
|
log_file = Path("logs/app.log")
|
|
if log_file.exists():
|
|
size_mb = log_file.stat().st_size / (1024 * 1024)
|
|
print(f" ✓ Log file exists: {log_file}")
|
|
print(f" Size: {size_mb:.2f} MB")
|
|
else:
|
|
print(f" ✗ Log file not found: {log_file}")
|
|
return False
|
|
except Exception as e:
|
|
print(f" ✗ Failed to check log file: {e}")
|
|
return False
|
|
|
|
# Test 3: Check database logs
|
|
print("\n[3] Checking database logs...")
|
|
try:
|
|
from app.core.database import SessionLocal
|
|
from app.modules.tenancy.models import ApplicationLog
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
count = db.query(ApplicationLog).count()
|
|
print(f" ✓ Database logs count: {count}")
|
|
|
|
if count > 0:
|
|
recent = (
|
|
db.query(ApplicationLog)
|
|
.order_by(ApplicationLog.timestamp.desc())
|
|
.limit(5)
|
|
.all()
|
|
)
|
|
|
|
print(" Recent logs:")
|
|
for log in recent:
|
|
print(f" [{log.level}] {log.logger_name}: {log.message[:60]}")
|
|
finally:
|
|
db.close()
|
|
except Exception as e:
|
|
print(f" ✗ Failed to query database logs: {e}")
|
|
# Don't fail the test - database logging might have initialization issues
|
|
|
|
# Test 4: Test log settings
|
|
print("\n[4] Testing log settings...")
|
|
try:
|
|
from app.core.database import SessionLocal
|
|
from app.modules.core.services.admin_settings_service import admin_settings_service
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
log_level = admin_settings_service.get_setting_value(
|
|
db, "log_level", "INFO"
|
|
)
|
|
max_size = admin_settings_service.get_setting_value(
|
|
db, "log_file_max_size_mb", 10
|
|
)
|
|
retention = admin_settings_service.get_setting_value(
|
|
db, "db_log_retention_days", 30
|
|
)
|
|
|
|
print(f" ✓ Log Level: {log_level}")
|
|
print(f" ✓ Max File Size: {max_size} MB")
|
|
print(f" ✓ Retention Days: {retention}")
|
|
finally:
|
|
db.close()
|
|
except Exception as e:
|
|
print(f" ✗ Failed to get log settings: {e}")
|
|
# Don't fail - settings might not be initialized yet
|
|
|
|
print("\n" + "=" * 70)
|
|
print("LOGGING SYSTEM TEST SUMMARY")
|
|
print("=" * 70)
|
|
print("✓ File logging: WORKING")
|
|
print("✓ Log rotation configured: READY")
|
|
print("✓ Database logging: Needs application context")
|
|
print("\nNote: Database logging will work when running through FastAPI")
|
|
print("=" * 70)
|
|
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Set up logging first
|
|
from app.core.logging import setup_logging
|
|
|
|
setup_logging()
|
|
|
|
success = test_logging_endpoints()
|
|
sys.exit(0 if success else 1)
|