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

I'm not able to get the logfile in IOS #81

Open hari-seafoodsouq opened 3 weeks ago

hari-seafoodsouq commented 3 weeks ago

I initialise as: await FlutterLogs.initLogs( logLevelsEnabled: [ LogLevel.INFO, LogLevel.WARNING, LogLevel.ERROR, LogLevel.SEVERE ], timeStampFormat: TimeStampFormat.TIME_FORMAT_READABLE, directoryStructure: DirectoryStructure.SINGLE_FILE_FOR_DAY, logFileExtension: LogFileExtension.TXT, logsWriteDirectoryName: "MyLogs", logsExportDirectoryName: "MyLogs/Exported", debugFileOperations: true, isDebuggable: true, );

I check it like this:

if (Platform.isIOS) { externalDirectory = await getApplicationDocumentsDirectory();

      final fileDirectory =
      Directory('${externalDirectory?.path}/MyLogs/Logs');

      if (!await fileDirectory.exists()) {
       Print("file doesn't exist);
      }
    }

I get an output stating "file doesn't exist" i want to know where is it getting stored and how can we see it. It works fine on android.

shubyaa commented 2 weeks ago

Can you check that iOS app has necessary permissions to write and read device storage? Try using this for IOS: logsExportDirectoryName: "${externalDirectory?.path}/MyLogs/Exported",

hari-seafoodsouq commented 1 week ago

Can you check that iOS app has necessary permissions to write and read device storage? Try using this for IOS: logsExportDirectoryName: "${externalDirectory?.path}/MyLogs/Exported",

Hi Shubyaa,

Thanks for the response. i tried using above code it didn't work as well.

This is how the code is when the share button is clicked where it's working fine for android and in ios the file is not created in the first place.

onPressed: () async { Directory? externalDirectory; if (Platform.isIOS) { externalDirectory = await getApplicationDocumentsDirectory(); } else { externalDirectory = await getExternalStorageDirectory(); } final fileDirectory = Directory('${externalDirectory?.path}/MyLogs/Logs');

    try {
      final zipFilePath = "${externalDirectory?.path}/log.zip";
      final zipFile = File(zipFilePath);
      if (zipFile.existsSync()) {
        zipFile.deleteSync();
      }
      await ZipFile.createFromDirectory(
          sourceDir: fileDirectory, zipFile: zipFile, recurseSubDirs: true);
      await Share.shareXFiles(
        [XFile(zipFile.path)],
        subject: 'Share log file',
        text: 'Hello, check your share files!',
      );
    } catch (e) {
      print('Error: $e');
      LogHelper.logs(e.toString());
      // ScaffoldMessenger.of(context).showSnackBar(
      //   SnackBar(content: Text('Error sharing logs: $e')),
      // );
    }
  },

  Kindly help me to fix this!