From 4349171acf51f632100a68d5e12280cb97c4d1af Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 29 Dec 2025 13:27:56 +0100 Subject: [PATCH] cleanup(contacts): Remove debug logging from last_seen feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature is now working correctly: - Parses 263 contacts (17 CLI + 226 REP + 20 ROOM) - Displays accurate last_seen timestamps with activity indicators - Shows relative time ("52 minutes ago", "1 year ago") - Color-coded status: 🟢 active, 🟡 recent, 🔴 inactive Removed excessive debug logging as it's no longer needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- app/meshcore/cli.py | 25 +++++-------------------- app/routes/api.py | 6 ------ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/app/meshcore/cli.py b/app/meshcore/cli.py index dcaa054..7adea79 100644 --- a/app/meshcore/cli.py +++ b/app/meshcore/cli.py @@ -561,19 +561,10 @@ def get_contacts_with_last_seen() -> Tuple[bool, Dict[str, Dict], str]: logger.warning(f"apply_to {contact_type} contact_info failed: {stderr}") continue # Skip this type, try next - logger.info(f"apply_to {contact_type} contact_info returned {len(stdout)} bytes") - - # Parse NDJSON output (newline-delimited JSON) - # Output may be prettified JSON, not line-delimited - # Try to extract all JSON objects from the text + # Parse prettified JSON output + # Output contains multiple JSON objects separated by newlines + # Use brace-matching to extract each complete object try: - # Log first 500 chars for debugging - logger.info(f"First 500 chars of {contact_type} output: {stdout[:500]}") - - # Strategy: JSON objects might be prettified (multiline) - # We need to find all { ... } blocks - import re - # Find all complete JSON objects (balanced braces) json_objects = [] depth = 0 @@ -594,21 +585,15 @@ def get_contacts_with_last_seen() -> Tuple[bool, Dict[str, Dict], str]: if 'public_key' in contact: json_objects.append(contact) except json.JSONDecodeError: - logger.debug(f"Failed to parse JSON object at position {start_idx}") + # Skip malformed JSON pass start_idx = None - parsed_count = len(json_objects) - # Add to contacts dict for contact in json_objects: contacts_dict[contact['public_key']] = contact - # Log first contact for debugging - if len(contacts_dict) == 1: - logger.info(f"Sample contact: public_key={contact['public_key'][:12]}..., last_advert={contact.get('last_advert', 'MISSING')}") - - logger.info(f"Parsed {parsed_count} contacts from {contact_type}") + logger.info(f"Parsed {len(json_objects)} contacts from {contact_type}") except Exception as e: logger.error(f"Error parsing {contact_type} output: {e}") diff --git a/app/routes/api.py b/app/routes/api.py index 5c49810..e783f34 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -1245,11 +1245,8 @@ def get_contacts_detailed_api(): success_detailed, contacts_detailed, error_detailed = cli.get_contacts_with_last_seen() if success_detailed: - logger.info(f"Got {len(contacts_detailed)} detailed contacts") - # Merge last_advert data with contacts # Match by public_key_prefix (first 12 chars of full public_key) - matched_count = 0 for contact in contacts: prefix = contact.get('public_key_prefix', '').lower() @@ -1258,10 +1255,7 @@ def get_contacts_detailed_api(): if full_key.lower().startswith(prefix): # Add last_seen timestamp contact['last_seen'] = details.get('last_advert', None) - matched_count += 1 break - - logger.info(f"Matched {matched_count} out of {len(contacts)} contacts with last_seen data") else: # If detailed fetch failed, log warning but still return contacts without last_seen logger.warning(f"Failed to get last_seen data: {error_detailed}")