feat: add privacy-safe structured logging
This commit is contained in:
@@ -10,6 +10,7 @@ from sqlalchemy.orm import Session
|
||||
from .config import settings
|
||||
from .database import SessionLocal
|
||||
from .importer import import_records
|
||||
from .logging_config import configure_logging
|
||||
from .models import OfficialRecordImport
|
||||
|
||||
|
||||
@@ -42,20 +43,24 @@ def run_due_import() -> bool:
|
||||
category=settings.official_records_category,
|
||||
)
|
||||
logger.info(
|
||||
"official import completed status=%s seen=%d created=%d updated=%d not_modified=%s",
|
||||
run.status.value, run.rows_seen, run.rows_created, run.rows_updated, run.not_modified,
|
||||
"official import completed",
|
||||
extra={
|
||||
"event": "official_import_completed", "result": run.status.value,
|
||||
"rows_seen": run.rows_seen, "rows_created": run.rows_created,
|
||||
"rows_updated": run.rows_updated, "not_modified": run.not_modified,
|
||||
},
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def main() -> None:
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
|
||||
logger.info("scheduler started interval_seconds=%d", settings.import_interval_seconds)
|
||||
configure_logging(settings.log_level)
|
||||
logger.info("scheduler started", extra={"event": "scheduler_started", "interval_seconds": settings.import_interval_seconds})
|
||||
while True:
|
||||
try:
|
||||
run_due_import()
|
||||
except Exception:
|
||||
logger.exception("scheduled official import failed")
|
||||
logger.exception("scheduled official import failed", extra={"event": "official_import_failed"})
|
||||
time.sleep(settings.import_interval_seconds)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user