Skip to content
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

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

Open
hari-seafoodsouq opened this issue Oct 18, 2024 · 9 comments
Open

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

hari-seafoodsouq opened this issue Oct 18, 2024 · 9 comments

Comments

@hari-seafoodsouq
Copy link

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
Copy link

shubyaa commented Oct 28, 2024

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
Copy link
Author

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!

@shubyaa
Copy link

shubyaa commented Nov 18, 2024

What errors you got while performing the code within try catch ? can you paste that error here?

@hari-seafoodsouq
Copy link
Author

Console:
flutter: Error: PlatformException(ZIP_ERROR, The file “Logs” couldn’t be opened because there is no such file., null, null)
flutter: flutter_logs: {} {} {PlatformException(ZIP_ERROR, The file “Logs” couldn’t be opened because there is no such file., null, null)} {INFO}

Initialising in main code:
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,
);

@shubyaa
Copy link

shubyaa commented Nov 21, 2024

The error says that the Flutter is looking for the file Logs, but in your initLogs, nothing is mentioned as Logs. Please check that from where the filename Logs is given.

@hari-seafoodsouq
Copy link
Author

The logs files are created or generated automatically through the package, as mentioned in the flutter package. The same process works fine in android but not on IOS.

@hari-seafoodsouq
Copy link
Author

And the initialising is given in initLogs is same as mentioned in the package. Kindly help me solve this issue.

FYI- flutter_logs: ^2.2.1

@shubyaa
Copy link

shubyaa commented Dec 2, 2024

I am not well aware of the exact cause, though I want you to know that the version I have used

  flutter_logs: ^2.1.11

It is because my project is quite older, so took the compatible version, you can give a try if possible ; )

@hari-seafoodsouq
Copy link
Author

Actually i'm using the same version too. Can you send me the FlutterLogs.initLogs code on main file and the code you use to get the logs? Does it work on ios for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants