Back to Blocks
Claude Terminal
Loading...
PXL-808Done
High
📱 Track sessions on device with cloud sync
b2-heradatasync
Logs your app usage sessions locally on your device and syncs them to the cloud.
> Technical Details
Implement a comprehensive session logging system to aid debugging of sync race conditions and other intermittent issues. The system captures all console output to local log files and syncs them to CloudKit for cross-device access.
Debugging sync race conditions (PXL-801) and other issues is extremely difficult with live logs because:
- ●Issues are intermittent and hard to reproduce
- ●By the time an issue is noticed, the relevant logs have scrolled away
- ●No way to capture logs from real-world usage sessions
- ●Can't debug issues that happen when not connected to Xcode
Create an on-device session logging system that:
- ●Captures all console output to a local log file per app session
- ●Syncs logs to CloudKit public database for cross-device access
- ●Tracks session status:
ACTIVE→TERMINATEDorCRASHED - ●Provides UI in Admin settings for viewing and exporting logs
- ●Auto-cleans old logs (7 days local, 30 days remote)
Session Lifecycle
- ●Session starts on app launch, ends only on true termination (not backgrounding)
- ●Logs background/foreground transitions within the same session
- ●Crash detection: missing
SESSION ENDmarker = crashed session
CloudKit Sync
- ●Uploads every 60 seconds while app is open
- ●Uploads immediately on foreground resume
- ●Final upload on termination with status
TERMINATED - ●On next launch after crash: upload previous session as
CRASHED - ●30-day retention with automatic cleanup
CloudKit Record Fields
- ●
userId(Supabase user ID) - ●
cloudKitUserId(CKRecord.ID) - ●
sessionId,filename,logFile(CKAsset) - ●
status: "active" / "terminated" / "crashed" - ●
startedAt,lastUpdatedAt,endedAt - ●
deviceModel,iosVersion,appVersion,fileSizeBytes
UI (Admin → Session Logs)
- ●Segment picker: Local / Cloud
- ●Current session with "Running" indicator
- ●Previous sessions with status badges (ACTIVE/TERMINATED/CRASHED)
- ●Device icons (📱 iPhone, 💻 iPad)
- ●Log detail view with search and export
- ●Delete all logs option
- ●
Packages/App/Sources/App/Services/SessionLogger.swift - ●
Packages/App/Sources/App/Services/SessionLogCloudKitManager.swift - ●
NutriKit/Views/Debug/SessionLogsView.swift - ●
NutriKit/Views/Debug/SessionLogDetailView.swift
- ●
NutriKit/NutriKitApp.swift - ●
NutriKit/Views/Debug/AdminSheet.swift - ●
Packages/App/Sources/App/Extensions/Logger.swift
- ●Per session: 2-4 MB typical
- ●Per user (30 days): ~100-200 MB
- ●1 PB capacity: Even 100K users = only 2% usage
- ●Blocks: PXL-801 (sync race condition debugging)
- ●Design doc: Session Logging System - Technical Design Document
Build instruction: Use -destination 'platform=iOS Simulator,name=iPhone 17 Pro' when building this project
Created Dec 30, 2025, 1:34 PM | Updated Feb 6, 2026, 11:46 AM