log refactor

This commit is contained in:
2026-05-12 19:30:15 +03:00
parent 1d59df2233
commit b17b5333c7
84 changed files with 5827 additions and 3908 deletions

View File

@@ -23,7 +23,10 @@ from typing import Any, Dict, Iterable, Optional
from sqlalchemy import create_engine, text
from sqlalchemy.exc import SQLAlchemyError
from src.core.logger import belief_scope, logger
from src.core.logger import belief_scope
from src.core.cot_logger import MarkerLogger
log = MarkerLogger("MigrateSqliteToPostgres")
# [/SECTION]
@@ -169,9 +172,7 @@ def _ensure_target_schema(engine) -> None:
def _migrate_config(engine, legacy_config_path: Optional[Path]) -> int:
with belief_scope("_migrate_config"):
if legacy_config_path is None:
logger.info(
"[_migrate_config][Action] No legacy config.json found, skipping"
)
log.reason("No legacy config.json found, skipping migration")
return 0
payload = json.loads(legacy_config_path.read_text(encoding="utf-8"))
@@ -332,9 +333,7 @@ def run_migration(
sqlite_path: Path, target_url: str, legacy_config_path: Optional[Path]
) -> Dict[str, int]:
with belief_scope("run_migration"):
logger.info(
"[run_migration][Entry] sqlite=%s target=%s", sqlite_path, target_url
)
log.reason("Starting migration from SQLite to PostgreSQL", payload={"sqlite_path": str(sqlite_path), "target_url": target_url})
if not sqlite_path.exists():
raise FileNotFoundError(f"SQLite source not found: {sqlite_path}")

View File

@@ -21,8 +21,11 @@ sys.path.append(str(Path(__file__).parent.parent.parent))
from src.core.config_manager import ConfigManager
from src.core.config_models import Environment
from src.core.logger import belief_scope, logger
from src.core.logger import belief_scope
from src.core.cot_logger import MarkerLogger
from src.core.superset_client import SupersetClient
log = MarkerLogger("SeedSupersetLoadTest")
# [/SECTION]
@@ -161,9 +164,7 @@ def _resolve_target_envs(env_ids: List[str]) -> Dict[str, Environment]:
env = Environment(**row)
configured[env.id] = env
except Exception as exc:
logger.warning(
f"[REFLECT] Failed loading environments from {config_path}: {exc}"
)
log.explore("Failed loading environments from config", payload={"config_path": str(config_path)}, error=str(exc))
for env_id in env_ids:
env = configured.get(env_id)
@@ -275,9 +276,7 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
templates_by_env[env_id] = _build_chart_template_pool(
client, args.template_pool_size, rng
)
logger.info(
f"[REASON] Environment {env_id}: loaded {len(templates_by_env[env_id])} chart templates"
)
log.reason("Loaded chart templates for environment", payload={"env_id": env_id, "template_count": len(templates_by_env[env_id])})
errors = 0
env_ids = list(env_map.keys())
@@ -289,9 +288,7 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
dashboard_title = _generate_unique_name("lt_dash", used_dashboard_names, rng)
if args.dry_run:
logger.info(
f"[REFLECT] Dry-run dashboard create: env={env_id}, title={dashboard_title}"
)
log.reflect("Dry-run dashboard create", payload={"env_id": env_id, "title": dashboard_title})
continue
try:
@@ -305,7 +302,7 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
created_dashboards[env_id].append(dashboard_id)
except Exception as exc:
errors += 1
logger.error(f"[EXPLORE] Failed creating dashboard in {env_id}: {exc}")
log.explore("Failed creating dashboard", payload={"env_id": env_id}, error=str(exc))
if errors >= args.max_errors:
raise RuntimeError(
f"Stopping due to max errors reached ({errors})"
@@ -355,10 +352,10 @@ def seed_superset_load_data(args: argparse.Namespace) -> Dict:
created_charts[env_id].append(chart_id)
if (index + 1) % 500 == 0:
logger.info(f"[REASON] Created {index + 1}/{args.charts} charts")
log.reason(f"Created {index + 1}/{args.charts} charts")
except Exception as exc:
errors += 1
logger.error(f"[EXPLORE] Failed creating chart in {env_id}: {exc}")
log.explore("Failed creating chart", payload={"env_id": env_id}, error=str(exc))
if errors >= args.max_errors:
raise RuntimeError(
f"Stopping due to max errors reached ({errors})"
@@ -385,9 +382,7 @@ def main() -> None:
with belief_scope("seed_superset_load_test.main"):
args = _parse_args()
result = seed_superset_load_data(args)
logger.info(
f"[COHERENCE:OK] Result summary: {json.dumps(result, ensure_ascii=True)}"
)
log.reflect("Seed load test complete", payload={"summary": result})
# [/DEF:main:Function]