Skip to content

feat(mobile): in-app debug logging with file export - #183

Merged
abarghoud merged 3 commits into
abarghoud:testingfrom
JordiMa:feat/mobile-debug-logs
Jul 8, 2026
Merged

feat(mobile): in-app debug logging with file export#183
abarghoud merged 3 commits into
abarghoud:testingfrom
JordiMa:feat/mobile-debug-logs

Conversation

@JordiMa

@JordiMa JordiMa commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Why

User-reported issues (like the recent Android push-activation reports) are hard to diagnose without visibility into what happened on the device. This adds an in-app debug log that users can export and attach to a bug report.

What

Logger (core/logging/)

  • appLogger singleton with info/warn/error(tag, message, data?).
  • Ring buffer of 5000 entries; consecutive duplicates are collapsed into one entry with a repeat counter (GET /alerts → 200 | 91ms (×3)), so the 30s alerts poll no longer eats the buffer. Attached data is truncated at 300 chars.
  • Persistent across sessions: debounced (1s) writes to a JSON file via expo-file-system on native, localStorage on web. Error-level entries are flushed immediately so they survive a crash.
  • Logging is fail-safe end to end (storage errors are swallowed).

What gets captured (central choke points, no per-screen wiring)

  • Every API request: method, path (query strings stripped), status, duration; network failures; session-refresh failures.
  • Every user interaction: taps, toggles, list rows and segment selections — logged inside the four core UI components (GlassButton, AppSwitch, ListRow, SegmentedControl).
  • Navigation: active screen on every navigation state change (nested navigators resolved) + shell gate transitions (Auth/Consent/Onboarding/Main).
  • Global JS errors: a wrapper around ErrorUtils logs fatal/non-fatal errors (name, message, stack head) before delegating to the previous handler.
  • Lifecycle & auth: session start (app version, platform), app foregrounding, token stored/cleared, login-callback outcomes (token received / missing scopes), Tesla-login open failures.
  • Push flow: token sync, permission missing → auto-disable, device registration, notification-preference updates (payload is boolean-only), logout cleanup failures.
  • Never logged: JWT/Tesla tokens (only their presence), push token (last 8 chars only), request bodies, text-input values, URLs with parameters.

Export UI (Settings → Support)

  • Export debug logs: writes sentryguard-logs-<date>.txt and opens the native share sheet via expo-sharing (falls back to a plain-text share if unavailable; downloads the file on web).
  • Clear debug logs.
  • en/fr localization.

Dependencies

  • expo-file-system ~19.0.23 — already shipped in every build (dependency of the expo package), now declared directly. No native rebuild needed for it.
  • expo-sharing ~14.0.8new native module: works in Expo Go now, standalone builds need the next native build (until then the text-share fallback applies).
  • yarn install --immutable verified.

Tests

  • 16 new logger tests (formatting, truncation, ring-buffer limit, duplicate collapsing, persistence across sessions, immediate error flush, debounced flush) + coverage for the global error handler and nested-route resolution.
  • Full suite: 148/148, nx typecheck mobile, lint and nx export mobile all pass.

Notes

SentryGuard debug logs
Exported at: 2026-07-03T21:26:36.953Z
App version: 1.0.0
Platform: android 36
Entries: 41
---
2026-07-03T21:26:10.338Z [INFO] app: Session started (v1.0.0, android 36)
2026-07-03T21:26:10.556Z [INFO] nav: Shell gate → Main
2026-07-03T21:26:12.095Z [INFO] api: GET /notifications/preferences → 200 | 54ms
2026-07-03T21:26:26.224Z [INFO] ui: Toggle "Notifications push" → false
2026-07-03T21:26:26.316Z [INFO] settings: Notification preference update | {"push_enabled":false,"critical_alerts_enabled":false}

Add a persistent ring-buffer logger (5000 entries, consecutive
duplicates collapsed with a repeat counter) stored via expo-file-system
on native and localStorage on web. Error-level entries are flushed
immediately so they survive crashes.

Instrumented central choke points so most activity is captured without
per-screen work: every API request (method, path, status, duration),
every screen change and shell gate, every button/toggle/row/segment
interaction through the core UI components, global JS errors, session
lifecycle, auth callback outcomes and the push registration flow.
Tokens, request bodies and text-input values are never logged.

Settings gains a Support section to export the logs as a .txt file
through the native share sheet (expo-sharing, with a text-share
fallback and a web download) and to clear them.
@JordiMa
JordiMa requested a review from abarghoud as a code owner July 3, 2026 21:39
@abarghoud abarghoud self-assigned this Jul 4, 2026
@abarghoud
abarghoud merged commit a3a060f into abarghoud:testing Jul 8, 2026
7 of 8 checks passed
@JordiMa
JordiMa deleted the feat/mobile-debug-logs branch July 8, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants