Skip to content

Feature/debug log viewer#98

Merged
ericgriffin merged 25 commits into
mainfrom
feature/debug-log-viewer
Mar 29, 2026
Merged

Feature/debug log viewer#98
ericgriffin merged 25 commits into
mainfrom
feature/debug-log-viewer

Conversation

@ericgriffin

Copy link
Copy Markdown
Member

Summary

Adds a hidden debug mode and full-featured debug log viewer to Submersion. When activated via an Easter egg in Settings, all application logging is written to a structured log file and can be viewed, filtered, searched, and exported from
within the app. Native platform logs (iOS/macOS, Android) are also captured and routed through the same system.

Changes

  • Add LogEntry, LogCategory, LogLevel data models with structured log line parsing
  • Add LogFileService with file I/O, rotation (keeps last ~50% when exceeding 5MB), and initialization guards
  • Enhance LoggerService with file writing, log categories, and native log callback support
  • Add DebugModeProvider with SharedPreferences persistence and Easter egg activation (tap version 7 times)
  • Add debug log viewer page with real-time updates, category filter chips, severity dropdown, and search
  • Add LogFilterBar and LogEntryTile widgets for the viewer UI
  • Add export actions: Share (system share sheet), Copy (clipboard), Save (file picker)
  • Add /settings/debug-logs route via go_router
  • Add iOS/macOS NativeLogger (Swift) routing os_log and NSLog calls to Flutter via Pigeon callback
  • Add Android NativeLogger (Kotlin) routing native logs to Flutter via Pigeon callback
  • Add libdivecomputer C log callback routing through NativeLogger
  • Migrate all repository and service logging from raw developer.log to categorized LoggerService calls
  • Initialize LogFileService at app startup (main.dart)
  • Add Debug section to mobile settings layout (visible only when debug mode enabled)

Test Plan

  • flutter test passes
  • flutter analyze passes
  • Manual testing on: macOS, iOS
  • Verify Easter egg activation (tap version label 7 times in Settings)
  • Verify log entries appear in real time in the debug log viewer
  • Verify category filters and severity dropdown filter correctly
  • Verify search filters log messages
  • Verify Share/Copy/Save export actions work
  • Verify "Clear Logs" removes all entries
  • Verify "Disable Debug Mode" navigates back to Settings and disables
  • Verify native logs (Bluetooth, libdivecomputer) appear with correct categories

Screenshots

Screenshot 2026-03-28 at 3 24 59 AM

Replaces positional error/stackTrace params with named params across all
call sites (~40 files), adds LogCategory support, and integrates
LogFileService for persistent log writing.
Long-pressing the version text 5 times in the About section enables debug mode.
When debug mode is active, a Debug section appears in the settings list above About,
routing to a placeholder DebugLogViewerPage (to be replaced in Task 9).
Creates NativeLogger singleton that forwards log events to Flutter via
the Pigeon onLogEvent callback while mirroring output to Android logcat.
Replaces all android.util.Log calls in DiveComputerHostApiImpl and
BleIoStream with NativeLogger using BLE/LDC category tagging.
Creates NativeLogger.swift in the shared darwin/Sources/LibDCDarwin/
directory to centralize log output — printing to the console and
forwarding each event to Flutter via DiveComputerFlutterApi.onLogEvent.
Replaces all NSLog calls in BleIoStream.swift and BleScanner.swift with
the appropriate NativeLogger level methods (d/i/w/e with BLE/SER
categories). Wires NativeLogger.flutterApi in both the macOS and iOS
plugin registration entry points, and adds the missing onLogEvent method
to the macOS-specific DiveComputerApi.g.swift. Symlinks for
NativeLogger.swift are added to both macos/Classes and ios/Classes so
each podspec picks up the file automatically.
… debug mode

Navigator.of(context).pop() crashes because the debug log viewer is rendered
inline as section content in the master-detail layout, not as a pushed route.
Using context.go('/settings') properly navigates back via go_router.
Cover LoggerService, debug log providers with filtering logic, DebugLogViewerPage, LogEntryTile, and LogFilterBar. Extend debug mode provider tests with ProviderContainer integration. Update Pigeon-generated API and DiveComputerService mock for log event stream.
Add broadcast stream to LoggerService and subscribe in logEntriesProvider via invalidateSelf() so the debug log viewer refreshes automatically during dive computer downloads and other logging activity.
Copilot AI review requested due to automatic review settings March 28, 2026 07:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an in-app “hidden” debug mode with persistent structured logging, native log capture, and a full debug log viewer UI (filter/search/export), while migrating existing logging call sites to the updated LoggerService API.

Changes:

  • Introduces structured log models (LogEntry, LogCategory, LogLevel) plus LogFileService for persistent log storage/rotation.
  • Adds debug-mode state (DebugModeNotifier) and a debug log viewer page with filters, search, and export actions.
  • Extends libdivecomputer_plugin Pigeon APIs and native implementations (Swift/Kotlin/C/JNI) to forward native logs into Flutter, and updates many repositories/services to the new logger API.

Reviewed changes

Copilot reviewed 86 out of 87 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/features/settings/presentation/widgets/log_filter_bar_test.dart Widget tests for category/severity filtering UI.
test/features/settings/presentation/widgets/log_entry_tile_test.dart Widget tests for log entry rendering (icon/tag/timestamp/message).
test/features/settings/presentation/providers/debug_mode_provider_test.dart Unit/provider tests for debug mode persistence and toggling.
test/features/settings/presentation/pages/debug_log_viewer_page_test.dart Widget tests for debug log viewer page UI states and actions.
test/features/import_wizard/presentation/widgets/dc_adapter_steps_test.dart Updates fake dive computer service for new log event API.
test/features/dive_computer/presentation/widgets/usb_search_test.dart Updates fake dive computer service for new log event API.
test/features/dive_computer/presentation/widgets/download_step_widget_test.dart Updates fake dive computer service for new log event API.
test/features/dive_computer/presentation/providers/download_notifier_fingerprint_test.mocks.dart Regenerates mocks to include new log event members.
test/core/services/logger_service_test.dart Adds tests for new LoggerService behavior and file logging.
test/core/services/log_file_service_test.dart Adds tests for file I/O, rotation, and init guards.
test/core/models/log_entry_test.dart Adds tests for parsing/formatting/equality of log entries.
packages/libdivecomputer_plugin/windows/dive_computer_api.g.h Adds onLogEvent Pigeon API for Windows C++ side.
packages/libdivecomputer_plugin/windows/dive_computer_api.g.cc Implements Windows C++ OnLogEvent message dispatch.
packages/libdivecomputer_plugin/pigeons/dive_computer_api.dart Declares new onLogEvent callback in the Pigeon schema.
packages/libdivecomputer_plugin/macos/Classes/libdc_wrapper.h Exposes C API to set libdivecomputer log callback.
packages/libdivecomputer_plugin/macos/Classes/libdc_wrapper.c Stores and applies the libdivecomputer log callback.
packages/libdivecomputer_plugin/macos/Classes/libdc_download.c Bridges libdivecomputer log func to the stored callback.
packages/libdivecomputer_plugin/macos/Classes/NativeLogger.swift Adds NativeLogger shim reference (path link).
packages/libdivecomputer_plugin/macos/Classes/LibdivecomputerPlugin.swift Wires NativeLogger to Flutter Pigeon API.
packages/libdivecomputer_plugin/macos/Classes/DiveComputerApi.g.swift Regenerated Swift Pigeon code with onLogEvent.
packages/libdivecomputer_plugin/linux/dive_computer_api.g.h Adds onLogEvent response types and API declarations.
packages/libdivecomputer_plugin/linux/dive_computer_api.g.cc Implements Linux onLogEvent messaging plumbing.
packages/libdivecomputer_plugin/lib/src/generated/dive_computer_api.g.dart Regenerated Dart Pigeon bindings with onLogEvent.
packages/libdivecomputer_plugin/lib/src/dive_computer_service.dart Exposes a Dart logEvents stream and implements onLogEvent.
packages/libdivecomputer_plugin/ios/Classes/NativeLogger.swift Adds NativeLogger shim reference (path link).
packages/libdivecomputer_plugin/ios/Classes/LibdivecomputerPlugin.swift Wires NativeLogger to Flutter Pigeon API on iOS.
packages/libdivecomputer_plugin/ios/Classes/DiveComputerApi.g.swift Regenerated iOS Swift Pigeon code with onLogEvent.
packages/libdivecomputer_plugin/darwin/Sources/LibDCDarwin/NativeLogger.swift Adds shared Darwin NativeLogger that forwards logs to Flutter.
packages/libdivecomputer_plugin/darwin/Sources/LibDCDarwin/DiveComputerHostApiImpl.swift Routes libdc + host logs through NativeLogger (and registers libdc callback).
packages/libdivecomputer_plugin/darwin/Sources/LibDCDarwin/BleScanner.swift Migrates BLE scanner logging to NativeLogger.
packages/libdivecomputer_plugin/android/src/main/kotlin/com/submersion/libdivecomputer/NativeLogger.kt Adds Android NativeLogger to forward logs to Flutter + logcat.
packages/libdivecomputer_plugin/android/src/main/kotlin/com/submersion/libdivecomputer/DiveComputerHostApiImpl.kt Migrates host logging to NativeLogger and wires flutter API into it.
packages/libdivecomputer_plugin/android/src/main/kotlin/com/submersion/libdivecomputer/DiveComputerApi.g.kt Regenerated Kotlin Pigeon code with onLogEvent.
packages/libdivecomputer_plugin/android/src/main/kotlin/com/submersion/libdivecomputer/BleIoStream.kt Migrates BLE I/O logging from Log.* to NativeLogger.
packages/libdivecomputer_plugin/android/src/main/cpp/libdc_jni.cpp Registers libdc log callback on Android native side (logcat).
lib/main.dart Initializes log file service and injects it via ProviderScope.
lib/features/trips/data/repositories/trip_repository.dart Updates error logging calls to named-parameter API.
lib/features/trips/data/repositories/liveaboard_details_repository.dart Updates error logging calls to named-parameter API.
lib/features/trips/data/repositories/itinerary_day_repository.dart Updates error logging calls to named-parameter API.
lib/features/tank_presets/data/repositories/tank_preset_repository.dart Updates error logging calls to named-parameter API.
lib/features/tags/data/repositories/tag_repository.dart Updates error logging calls to named-parameter API.
lib/features/statistics/data/repositories/statistics_repository.dart Updates error logging calls to named-parameter API.
lib/features/signatures/data/services/signature_storage_service.dart Updates error logging calls to named-parameter API.
lib/features/settings/presentation/widgets/settings_list_content.dart Shows Debug section when debug mode is enabled.
lib/features/settings/presentation/widgets/log_filter_bar.dart Adds log filter UI (category chips + severity dropdown).
lib/features/settings/presentation/widgets/log_entry_tile.dart Adds UI row for rendering a log entry.
lib/features/settings/presentation/providers/settings_providers.dart Updates logging call to new named-parameter API.
lib/features/settings/presentation/providers/debug_mode_provider.dart Adds debug mode persistence provider (SharedPreferences).
lib/features/settings/presentation/providers/debug_log_providers.dart Adds log file provider, live reloading, filtering, and export helpers.
lib/features/settings/presentation/pages/settings_page.dart Adds Debug section content + debug-mode “Easter egg” activation hook.
lib/features/settings/presentation/pages/debug_log_viewer_page.dart Adds debug log viewer page (search/filter/export/clear/disable).
lib/features/settings/data/repositories/diver_settings_repository.dart Updates error logging calls to named-parameter API.
lib/features/notifications/data/repositories/scheduled_notification_repository.dart Updates error logging calls to named-parameter API.
lib/features/media/data/services/metadata_write_service.dart Updates error logging calls to named-parameter API.
lib/features/media/data/services/media_import_service.dart Updates error logging calls to named-parameter API.
lib/features/media/data/services/exif_write_service.dart Updates error logging calls to named-parameter API.
lib/features/media/data/services/asset_resolution_service.dart Updates error logging calls to named-parameter API.
lib/features/media/data/repositories/media_repository.dart Updates error logging calls to named-parameter API.
lib/features/equipment/data/repositories/equipment_repository_impl.dart Updates error logging calls to named-parameter API.
lib/features/divers/data/repositories/diver_repository.dart Updates error logging calls to named-parameter API.
lib/features/dive_types/data/repositories/dive_type_repository.dart Updates error logging calls to named-parameter API.
lib/features/dive_sites/data/repositories/site_repository_impl.dart Updates error logging calls to named-parameter API.
lib/features/dive_log/presentation/providers/profile_analysis_provider.dart Updates error logging calls to named-parameter API.
lib/features/dive_log/data/repositories/dive_computer_repository_impl.dart Updates error logging calls to named-parameter API.
lib/features/dive_computer/presentation/providers/discovery_providers.dart Listens to native log events and routes them into LoggerService.
lib/features/dive_centers/data/repositories/dive_center_repository.dart Updates error logging calls to named-parameter API.
lib/features/courses/data/repositories/course_repository.dart Updates error logging calls to named-parameter API.
lib/features/certifications/data/repositories/certification_repository.dart Updates error logging calls to named-parameter API.
lib/features/buddies/data/repositories/buddy_repository.dart Updates error logging calls to named-parameter API.
lib/features/buddies/data/repositories/buddy_merge_repository.dart Updates error logging calls to named-parameter API.
lib/features/backup/data/services/backup_service.dart Updates error logging calls to named-parameter API.
lib/core/services/sync/sync_service.dart Updates error/warn logging calls to named-parameter API.
lib/core/services/sync/sync_initializer.dart Updates error logging calls to named-parameter API.
lib/core/services/sync/sync_data_serializer.dart Updates error logging calls to named-parameter API.
lib/core/services/logger_service.dart Expands logger to support categories, file writes, and live log stream.
lib/core/services/log_file_service.dart Adds log file I/O, rotation, and init guards.
lib/core/services/location_service.dart Updates error logging calls to named-parameter API.
lib/core/services/cloud_storage/icloud_storage_provider.dart Updates error logging calls to named-parameter API.
lib/core/services/cloud_storage/icloud_native_service.dart Updates warning logging calls to named-parameter API.
lib/core/services/cloud_storage/google_drive_storage_provider.dart Updates error logging calls to named-parameter API.
lib/core/services/background_service.dart Updates error logging calls to named-parameter API.
lib/core/router/app_router.dart Adds /settings/debug-logs route.
lib/core/models/log_entry.dart Adds structured log models and parsing/formatting.
lib/core/data/repositories/sync_repository.dart Updates error/warn logging calls to named-parameter API.

Comment thread lib/features/settings/presentation/pages/debug_log_viewer_page.dart
Comment thread lib/main.dart Outdated
Comment thread lib/core/services/logger_service.dart
Comment thread lib/features/settings/presentation/pages/settings_page.dart
Comment thread lib/features/settings/presentation/pages/settings_page.dart

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Two provider naming convention violations found per CLAUDE.md (rule: <noun>NotifierProvider for mutable state). See inline comments.

Comment thread lib/features/settings/presentation/providers/debug_log_providers.dart Outdated
Comment thread lib/features/settings/presentation/providers/debug_mode_provider.dart Outdated
Connect LoggerService file backend to DebugModeNotifier so enabling debug mode starts file logging and disabling stops it. Rename providers to follow Riverpod conventions (debugModeNotifierProvider, logFilterNotifierProvider). Serialize LogFileService writes to prevent rotation races. Change debug mode activation from long-press to tap.
… coverage

Add error-path tests for 20+ repositories to verify methods propagate database errors correctly. Extend debug log viewer widget tests with
error state, search filtering, and clipboard copy scenarios. Add settings page tests for debug mode section visibility.
@ericgriffin
ericgriffin merged commit f5be45b into main Mar 29, 2026
24 checks passed
@ericgriffin
ericgriffin deleted the feature/debug-log-viewer branch March 29, 2026 00:19
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