umair13adil / flutter_logs

An extensive logging framework developed for flutter apps.
https://itnext.io/sending-logs-from-flutter-apps-in-real-time-using-elk-stack-mqtt-c24fa0cb9802
Apache License 2.0
39 stars 28 forks source link

FlutterLogs.exportLogs doesn't return (await hangs) if there are 0 files #39

Open MrCsabaToth opened 2 years ago

MrCsabaToth commented 2 years ago

My code is FlutterLogs.exportLogs(exportType: ExportType.ALL); as a preparation for exporting all logs. My app has a button the user can tap to export logs. However if there wasn't any logging going on so far (0 files) then the function call doesn't return. I see this in the debug log output:

I/ExportTypes(17208): getLogsForAllInRoot: Path: /storage/emulated/0/Android/data/dev.csaba.track_my_indoor_exercise/files/Logs/Logs/, Files: 0

I either need it to return with some special code or need a function call which tells me if there's anything to export so I can enable / disable the button. Currently the QA testers report this as a bug to me because they are clicking on the button and "nothing is happening". I'd like to display a dialog if there's nothing to export.

MrCsabaToth commented 2 years ago

I'm trying to debug this. The problem is that when there are no files, then the FlutterLogs.channel.setMethodCallHandler((call) async { handler (see https://github.com/umair13adil/flutter_logs/blob/3ac8a1a9c02f31ca187950e9d5b917c4367b1ec5/example/lib/main.dart#L51) is not fired. The case when there are no files is this:

https://github.com/umair13adil/RxLogs/blob/f199b3c89cf510a15b66307c9bf389af4af6fde1/plog/src/main/java/com/blackbox/plog/pLogs/exporter/LogExporter.kt#L110

            if (filesToSend.isEmpty()) {
                if (!emitter.isDisposed)
                    emitter.onError(Throwable("No Files to zip!"))
            }

In fun compressPackage. I'm not sure yet how to bubble that up to the Dart layer, or why is it not bubbling up right now. There's a throwable generated there but I don't see that in Logcat, so it's swallowed somewhere. If I cannot bubble it up then maybe there could be a new call on the API to check if there are files? That might be more work due to API change and RxLogs need to be changed as well.

MrCsabaToth commented 2 years ago

There's nothing in Logcat besides I/ExportTypes(20611): getLogsForAllInRoot: Path: /storage/emulated/0/Android/data/dev.csaba.track_my_indoor_exercise/files/Logs/Logs/, Files: 0, and nothing bubbles up.

MrCsabaToth commented 2 years ago

Maybe the emitter is disposed? (if (!emitter.isDisposed)). I'd expect to see the "No Files to zip!" in the logs to appear somewhere. The control flow doesn't reach this point either https://github.com/umair13adil/flutter_logs/blob/3ac8a1a9c02f31ca187950e9d5b917c4367b1ec5/android/src/main/kotlin/com/flutter/logs/plogs/flutter_logs/FlutterLogsPlugin.kt#L233 (or at least I don't see exportPLogs: PLog Error: log entries either in LogCat.

ced1check commented 7 months ago

Running version 2.1.11 on Android, it seems exportLogs never returns no matter what. I have log files, I can see the ZIP file created fine, but onComplete or then never runs:

    FlutterLogs.exportLogs(exportType: ExportType.ALL).then((value) {
      logInfo(message: 'Finished exporting FlutterLogs...');
    });

Haven't tried on iOS yet.