flutter_logs icon indicating copy to clipboard operation
flutter_logs copied to clipboard

setMethodCallHandler callback not getting hit

Open vysakhvasanth opened this issue 1 year ago • 4 comments

I'm using the latest version 2.1.10.

When I export the logs, I'm trying to capture the callback to upload file to a server. But the callback registered is not getting hit.

FlutterLogs.channel.setMethodCallHandler((call) async {
      if (call.method == 'logsExported') {
        var zipName = call.arguments.toString();
      } else if (call.method == 'logsPrinted') {
        print(call.arguments.toString());
      }
}

vysakhvasanth avatar Jan 27 '23 11:01 vysakhvasanth

I've registered the callback in the main.dart entry point right after the setup call FlutterLogs.initLogs

vysakhvasanth avatar Jan 27 '23 11:01 vysakhvasanth

Same problem here with v2.1.11 on Android, not sure what I'm doing wrong, I run this:

await FlutterLogs.init(...);

Then copy-pasted the channel setup from readme added a log at the very start but it never shows!?

FlutterLogs.channel.setMethodCallHandler((call) async {
  logInfo(message: 'Received FlutterLogs callback: ${call.method}');
}

In console I see this, but not the message above:

I/ExportTypes( 4479): getLogsForAllInRoot: Path: /storage/emulated/0/Android/data/com.my.app/files/Logs/, Files: 2
I/PLogger_DEBUG( 4479): Adding directory: /storage/emulated/0/Android/data/com.my.app/files/exported/Temp/21112023/
I/PLogger_DEBUG( 4479): Adding file: /storage/emulated/0/Android/data/com.my.app/files/exported/Temp/21112023/2111202319.log
I/PLogger_DEBUG( 4479): Adding file: /storage/emulated/0/Android/data/com.my.app/files/exported/Temp/21112023/2111202320.log
I/PLogger_DEBUG( 4479): Output Zip: 21112023_200738_PM_all_[2].zip

I also try to use whenComplete or then on the exportLogs() call, it appears that the call never complete:

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

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

Will try on iOS asap.

@vysakhvasanth Did you find a solution?

ced1check avatar Nov 21 '23 19:11 ced1check

Ended-up using flutter_archive to export logs into a ZIP file:

      Directory dir = Directory("${externalDirectory.path}/Logs");

      final zipFile = File("${externalDirectory.path}/Logs_${DateFormat('yyyy-MM-dd_HH-mm').format(DateTime.now())}.zip");
      await ZipFile.createFromDirectory(sourceDir: dir, zipFile: zipFile, recurseSubDirs: true);

      logInfo(message: "Logs zipped into ${zipFile.path}");

ced1check avatar Nov 21 '23 20:11 ced1check

@ced1check what did you end up with?

neiljaywarner avatar Jan 10 '24 21:01 neiljaywarner