Files
orion/scripts/test_logging_system.py
Samir Boulahtit 4e28d91a78 refactor: migrate templates and static files to self-contained modules
Templates Migration:
- Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.)
- Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.)
- Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms)
- Migrate public templates to modules (billing, marketplace, cms)
- Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/)
- Migrate letzshop partials to marketplace module

Static Files Migration:
- Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file)
- Migrate vendor JS to modules: tenancy (4 files), core (2 files)
- Migrate shared JS: vendor-selector.js to core, media-picker.js to cms
- Migrate storefront JS: storefront-layout.js to core
- Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/)
- Update all template references to use module_static paths

Naming Consistency:
- Rename static/platform/ to static/public/
- Rename app/templates/platform/ to app/templates/public/
- Update all extends and static references

Documentation:
- Update module-system.md with shared templates documentation
- Update frontend-structure.md with new module JS organization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 14:34:16 +01:00

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 models.database.admin 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)