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
40 stars 33 forks source link

setMethodCallHandler callback not getting hit #50

Closed vysakhvasanth closed 2 months ago

vysakhvasanth commented 1 year ago

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 commented 1 year ago

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

ced1check commented 1 year ago

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 commented 1 year ago

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}");
neiljaywarner commented 10 months ago

@ced1check what did you end up with?

umair13adil commented 2 months ago
Screenshot 2024-09-07 at 1 40 25 PM