Update logging levels in ingestion_processor.py and import_markdown.py for improved visibility
Change debug logs to info and warning levels in ingestion_processor.py to enhance the visibility of change detection processes, including hash comparisons and artifact checks. Additionally, ensure .env is loaded before logging setup in import_markdown.py to correctly read the DEBUG environment variable. These adjustments aim to improve traceability and debugging during ingestion workflows.
This commit is contained in:
parent
7cb8fd6602
commit
de5db09b51
|
|
@ -269,8 +269,8 @@ class IngestionService:
|
|||
# Prüft Hash VOR der Verarbeitung, um redundante Ingestion zu vermeiden
|
||||
old_payload = None if force_replace else fetch_note_payload(self.client, self.prefix, note_id)
|
||||
|
||||
# WP-24c v4.5.9-DEBUG: Erweiterte Diagnose-Logs für Change-Detection
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] Start für '{note_id}': force_replace={force_replace}, old_payload={old_payload is not None}")
|
||||
# WP-24c v4.5.9-DEBUG: Erweiterte Diagnose-Logs für Change-Detection (INFO-Level für Sichtbarkeit)
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] Start für '{note_id}': force_replace={force_replace}, old_payload={old_payload is not None}")
|
||||
|
||||
content_changed = True
|
||||
hash_match = False
|
||||
|
|
@ -281,36 +281,41 @@ class IngestionService:
|
|||
new_h = note_pl.get("hashes", {}).get(h_key)
|
||||
old_h = old_payload.get("hashes", {}).get(h_key)
|
||||
|
||||
# WP-24c v4.5.9-DEBUG: Detaillierte Hash-Diagnose
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] Hash-Vergleich für '{note_id}':")
|
||||
logger.debug(f" -> Hash-Key: '{h_key}'")
|
||||
logger.debug(f" -> Active Hash-Mode: '{self.active_hash_mode or 'full'}'")
|
||||
logger.debug(f" -> New Hash vorhanden: {bool(new_h)}")
|
||||
logger.debug(f" -> Old Hash vorhanden: {bool(old_h)}")
|
||||
# WP-24c v4.5.9-DEBUG: Detaillierte Hash-Diagnose (INFO-Level)
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] Hash-Vergleich für '{note_id}':")
|
||||
logger.info(f" -> Hash-Key: '{h_key}'")
|
||||
logger.info(f" -> Active Hash-Mode: '{self.active_hash_mode or 'full'}'")
|
||||
logger.info(f" -> New Hash vorhanden: {bool(new_h)}")
|
||||
logger.info(f" -> Old Hash vorhanden: {bool(old_h)}")
|
||||
if new_h:
|
||||
logger.debug(f" -> New Hash (erste 32 Zeichen): {new_h[:32]}...")
|
||||
logger.info(f" -> New Hash (erste 32 Zeichen): {new_h[:32]}...")
|
||||
if old_h:
|
||||
logger.debug(f" -> Old Hash (erste 32 Zeichen): {old_h[:32]}...")
|
||||
logger.debug(f" -> Verfügbare Hash-Keys in new: {list(note_pl.get('hashes', {}).keys())}")
|
||||
logger.debug(f" -> Verfügbare Hash-Keys in old: {list(old_payload.get('hashes', {}).keys())}")
|
||||
logger.info(f" -> Old Hash (erste 32 Zeichen): {old_h[:32]}...")
|
||||
logger.info(f" -> Verfügbare Hash-Keys in new: {list(note_pl.get('hashes', {}).keys())}")
|
||||
logger.info(f" -> Verfügbare Hash-Keys in old: {list(old_payload.get('hashes', {}).keys())}")
|
||||
|
||||
if new_h and old_h:
|
||||
hash_match = (new_h == old_h)
|
||||
if hash_match:
|
||||
content_changed = False
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] ✅ Hash identisch für '{note_id}': {h_key} = {new_h[:16]}...")
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] ✅ Hash identisch für '{note_id}': {h_key} = {new_h[:16]}...")
|
||||
else:
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] ❌ Hash geändert für '{note_id}': alt={old_h[:16]}..., neu={new_h[:16]}...")
|
||||
logger.debug(f" -> Hash-Unterschied: Erste unterschiedliche Position: {next((i for i, (a, b) in enumerate(zip(new_h, old_h)) if a != b), 'keine')}")
|
||||
logger.warning(f"🔍 [CHANGE-DETECTION] ❌ Hash geändert für '{note_id}': alt={old_h[:16]}..., neu={new_h[:16]}...")
|
||||
# Finde erste unterschiedliche Position
|
||||
diff_pos = next((i for i, (a, b) in enumerate(zip(new_h, old_h)) if a != b), None)
|
||||
if diff_pos is not None:
|
||||
logger.info(f" -> Hash-Unterschied: Erste unterschiedliche Position: {diff_pos}")
|
||||
else:
|
||||
logger.info(f" -> Hash-Unterschied: Längen unterschiedlich (new={len(new_h)}, old={len(old_h)})")
|
||||
else:
|
||||
# WP-24c v4.5.9: Wenn Hash fehlt, als geändert behandeln (Sicherheit)
|
||||
logger.warning(f"⚠️ [CHANGE-DETECTION] Hash fehlt für '{note_id}': new_h={bool(new_h)}, old_h={bool(old_h)}")
|
||||
logger.debug(f" -> Grund: Hash wird als 'geändert' behandelt, da Hash-Werte fehlen")
|
||||
logger.info(f" -> Grund: Hash wird als 'geändert' behandelt, da Hash-Werte fehlen")
|
||||
else:
|
||||
if force_replace:
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': force_replace=True -> überspringe Hash-Check")
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] '{note_id}': force_replace=True -> überspringe Hash-Check")
|
||||
elif not old_payload:
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Keine alte Payload gefunden -> erste Verarbeitung oder gelöscht")
|
||||
logger.warning(f"🔍 [CHANGE-DETECTION] '{note_id}': ⚠️ Keine alte Payload gefunden -> erste Verarbeitung oder gelöscht")
|
||||
|
||||
# WP-24c v4.5.9: Strikte Logik - überspringe komplett wenn Hash identisch
|
||||
# WICHTIG: Artifact-Check NACH Hash-Check, da purge_before die Artefakte löschen kann
|
||||
|
|
@ -323,11 +328,11 @@ class IngestionService:
|
|||
return {**result, "status": "unchanged", "note_id": note_id, "reason": "hash_identical"}
|
||||
elif not force_replace and old_payload and not hash_match:
|
||||
# WP-24c v4.5.9-DEBUG: Hash geändert - erlaube Verarbeitung
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Hash geändert -> erlaube Verarbeitung")
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] '{note_id}': Hash geändert -> erlaube Verarbeitung")
|
||||
|
||||
# WP-24c v4.5.9: Hash geändert oder keine alte Payload - prüfe Artefakte für normale Verarbeitung
|
||||
c_miss, e_miss = artifacts_missing(self.client, self.prefix, note_id)
|
||||
logger.debug(f"🔍 [CHANGE-DETECTION] '{note_id}': Artifact-Check: c_miss={c_miss}, e_miss={e_miss}")
|
||||
logger.info(f"🔍 [CHANGE-DETECTION] '{note_id}': Artifact-Check: c_miss={c_miss}, e_miss={e_miss}")
|
||||
|
||||
if not apply:
|
||||
return {**result, "status": "dry-run", "changed": True, "note_id": note_id}
|
||||
|
|
|
|||
|
|
@ -71,12 +71,15 @@ from pathlib import Path
|
|||
from typing import List, Dict, Any
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# WP-24c v4.5.9: Lade .env VOR dem Logging-Setup, damit DEBUG=true korrekt gelesen wird
|
||||
load_dotenv()
|
||||
|
||||
# Root Logger Setup: Nutzt zentrale setup_logging() Funktion
|
||||
# WP-24c v4.4.0-DEBUG: Aktiviert DEBUG-Level für End-to-End Tracing
|
||||
# Kann auch über Umgebungsvariable DEBUG=true gesteuert werden
|
||||
from app.core.logging_setup import setup_logging
|
||||
|
||||
# Bestimme Log-Level basierend auf DEBUG Umgebungsvariable
|
||||
# Bestimme Log-Level basierend auf DEBUG Umgebungsvariable (nach load_dotenv!)
|
||||
debug_mode = os.getenv("DEBUG", "false").lower() == "true"
|
||||
log_level = logging.DEBUG if debug_mode else logging.INFO
|
||||
|
||||
|
|
@ -234,7 +237,8 @@ async def main_async(args):
|
|||
|
||||
def main():
|
||||
"""Einstiegspunkt und Argument-Parsing."""
|
||||
load_dotenv()
|
||||
# WP-24c v4.5.9: load_dotenv() wurde bereits beim Modul-Import aufgerufen
|
||||
# (oben, vor dem Logging-Setup, damit DEBUG=true korrekt gelesen wird)
|
||||
|
||||
# Standard-Präfix aus Umgebungsvariable oder Fallback
|
||||
default_prefix = os.getenv("COLLECTION_PREFIX", "mindnet")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user