-
Notifications
You must be signed in to change notification settings - Fork 17
Feat: Share and Save logs files #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…at/logging-phases-3&4
Create LoggerExportService with methods to: - Generate timestamped filenames (mostro_logs_YYYY-MM-DD_HH-MM-SS.txt) - Convert LogEntry list to formatted text with metadata header - Export logs using FilePicker.saveFile() for Android 13+ SAF compatibility - Export logs to temp directory for sharing - Share logs via native share sheet using Share.shareXFiles()
Create LogsActionsMenu with PopupMenuButton containing three actions: - Save: Export logs to user-selected location via FilePicker - Share: Share logs via native system share sheet - Clear: Delete all logs with confirmation dialog Features: - Uses HeroIcons for consistent iconography - Menu items disabled when no logs available - Proper error handling with SnackBar feedback - Success message without showing file path for cleaner UX
Replace individual IconButtons with LogsActionsMenu in AppBar. Remove methods moved to menu widget. Clean up lifecycle observer. Simplified scope: manual save only when user explicitly requests it.
Clean up Settings model by removing logExportPath field and related code. Simplified implementation: no default folder configuration.
Add translations in all languages (EN, ES, IT) for: - saveLogs, logsExportSuccess, logsExportError - shareLogsError, shareLogs - exportSettings, close Simplified success message without showing file path.
Mark Phase 5 as completed with implemented features: - Manual export via hamburger menu - Save logs to user-selected location using FilePicker - Share logs via native system share sheet - Generate timestamped .txt files - Clear logs with confirmation dialog - Simplified scope: manual save only, no auto-save or default folder
WalkthroughReplaces automatic log persistence with manual export/share/clear. Adds LoggerExportService to format/save/share logs, a LogsActionsMenu UI exposing Save/Share/Clear, replaces the appbar clear button, updates lifecycle observer hooks, and adds localization and docs entries for the new flow. Phase bumped to 6. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LogsActionsMenu
participant LoggerExportService
participant FilePicker
participant FileSystem
participant SnackBar
User->>LogsActionsMenu: Tap "Save Logs"
LogsActionsMenu->>LoggerExportService: exportLogsToFolder(logs, strings)
LoggerExportService->>LoggerExportService: _generateFilename() and _logsToText(logs)
LoggerExportService->>FilePicker: prompt save location
FilePicker->>User: show file picker
User->>FilePicker: selects destination
FilePicker->>FileSystem: write UTF-8 bytes to chosen path
FileSystem-->>LoggerExportService: return saved path
LoggerExportService-->>LogsActionsMenu: return path/null
LogsActionsMenu->>SnackBar: show success or error message
sequenceDiagram
participant User
participant LogsActionsMenu
participant LoggerExportService
participant TempFS
participant SharePlugin
participant NativeShare
User->>LogsActionsMenu: Tap "Share Logs"
LogsActionsMenu->>LoggerExportService: exportLogsForSharing(logs, strings)
LoggerExportService->>LoggerExportService: _logsToText(logs)
LoggerExportService->>TempFS: write temp file
TempFS-->>LoggerExportService: return temp file
LoggerExportService->>SharePlugin: shareLogs(file, subject, text)
SharePlugin->>NativeShare: invoke native share sheet
NativeShare-->>User: display share options
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🤖 Fix all issues with AI agents
In `@lib/features/logs/widgets/logs_actions_menu.dart`:
- Around line 121-129: In the catch block in logs_actions_menu.dart where
ScaffoldMessenger.of(context).showSnackBar is used, stop interpolating the raw
exception ($e) into the SnackBar content; instead display a generic localized
message (use S.of(context)!.logsExportError or add a new localized key like
logsExportErrorGeneric) and keep the full error/stackTrace passed to
_logger.e('_logger.e(...)') for debugging; update both the catch block shown and
the similar handler around the other occurrence (the second SnackBar at 138-145)
so no raw exception text is shown to users while preserving logging.
In `@lib/l10n/intl_en.arb`:
- Around line 1296-1303: The ARB contains duplicate keys "shareLogs" and "close"
which will break parsing; remove the duplicated entries from this block (or
rename them to unique keys if these strings must be distinct), ensuring only one
definition of "shareLogs" and "close" remains in the intl_en.arb file and update
any callers to use the new key name if you choose to rename.
In `@lib/l10n/intl_es.arb`:
- Around line 1272-1279: The ARB snippet contains duplicate localization keys
"shareLogs" and "close" which will break gen_l10n; remove the duplicate entries
from this block in lib/l10n/intl_es.arb (or rename them if these strings must be
distinct) and ensure only a single definition of "shareLogs" and "close"
remains; update any callers only if you rename the keys so code references the
new key names consistently.
In `@lib/l10n/intl_it.arb`:
- Around line 1327-1334: Remove the duplicate ARB keys causing parse/generation
failures by locating the repeated keys "shareLogs" and "close" in the current
diff (they are redefined alongside "viewAndExportLogs", "saveLogs", etc.) and
either delete these duplicate entries or rename them to a unique key if a
different label is intended; ensure only one definition of "shareLogs" and one
of "close" remain in the ARB file and run the intl generation to confirm the
error is resolved.
In `@lib/services/logger_export_service.dart`:
- Around line 19-25: Add the specified localization keys to the ARB files:
logsHeaderTitle, logsGeneratedLabel, logsTotalLabel, logsShareSubject,
logsShareText, and logsEmptyMessage (map to existing noLogsAvailable if
present). In lib/services/logger_export_service.dart, modify the
LoggerExportService export methods (e.g., the method that builds the export
string / share payload) to accept these localized string parameters:
logsHeaderTitle, logsGeneratedLabel, logsTotalLabel, logsShareSubject,
logsShareText, and logsEmptyMessage; replace hard-coded literals ('Mostro P2P
Application Logs', 'Generated', 'Total logs', 'Mostro P2P Logs', 'Application
logs from Mostro P2P', 'No logs available') with the passed parameters (use
logsEmptyMessage for the empty-case return), and update callers (the Widget with
BuildContext) to pass S.of(context).logsHeaderTitle etc. when invoking the
service.
🧹 Nitpick comments (2)
lib/features/logs/widgets/logs_actions_menu.dart (1)
11-15: Make the widgetconstby hoisting the logger to a static field.This improves immutability and avoids rebuilding a new
Loggerfor each widget instance.
As per coding guidelines, preferconstconstructors where possible.♻️ Proposed change
class LogsActionsMenu extends ConsumerWidget { - final _logger = Logger(); + static final Logger _logger = Logger(); - LogsActionsMenu({super.key}); + const LogsActionsMenu({super.key});lib/services/logger_export_service.dart (1)
50-68: Consider cleaning up the temp file after sharing.The temp directory can grow if share files are never deleted. A
try/finallyaroundShare.shareXFileskeeps storage tidy.♻️ Possible cleanup
static Future<void> shareLogs(File file) async { final xFile = XFile(file.path); - await Share.shareXFiles( - [xFile], - subject: 'Mostro P2P Logs', - text: 'Application logs from Mostro P2P', - ); + try { + await Share.shareXFiles( + [xFile], + subject: 'Mostro P2P Logs', + text: 'Application logs from Mostro P2P', + ); + } finally { + try { + if (await file.exists()) { + await file.delete(); + } + } catch (_) { + // swallow cleanup errors + } + } }
Refactors log export and sharing to utilize localized strings for file content, subject, and text. This change ensures a consistent user experience across different languages when exporting and sharing logs by using the app's localization system. It also includes a title to the logs file, generated timestamp and the total number of logs written.
Catrya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BraCR10 me funciona bien, pero cuando comparto los logs, por ejemplo los envio a telegram, si quiero regresar a la app no puedo, se queda dentro de telegram aunque intente ir hacia atras, debo cerrar mostro app y volverla a abrir para que salga de ahi.
Lo otro es que si acabo de enviar los logs a telegram, e intento nuevamente no puedo, sino que debo cerrar mostro app y volverla a abrir.
Cuando puedas revisa eso por si acaso, no estoy segura de si es un problema de telegram propiamente.
Catrya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK al parecer el problma que me da es de telegram, no de la app de mostro
grunch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
Phase 5: File Export & Persistence
This PR implements manual log export functionality with a menu UI.
What's Included
Export Service:
LoggerExportServicefor saving and sharing logsUI Updates:
Testing
Navigate to: Settings → Dev Tools → Logs Report
See
docs/LOGGING_IMPLEMENTATION.mdfor details.Summary by CodeRabbit
New Features
Behavior Change
Localization
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.