MATLAB Answers

No log file generated for standalone app

26 views (last 30 days)
Michael
Michael on 7 Jul 2021
Answered: Michael on 16 Jul 2021
I am on macOS Catalina trying to deploy a standalone Matlab app using the application compliler. I am on R2020b.
I check off the 'Create log file' option in the Application Compiler and provide a filename that complies with the special character requirements. When I try running my app, I don't ever see a log file generated. I have tried running it after installing it, from the 'for_testing' folder, and from the 'for_redistribution_files_only' folders with no success. My problem is that I am getting errors in my app when deployed as an application, but not when run within appdesigner. Without the log file, I can't debug.
What am I doing wrong? Thanks.
  6 Comments
Michael
Michael on 9 Jul 2021
Just got in touch with Mathworks support about this. If you run the application via Terminal by navigating to the application folder and using the terminal command
./run_<your_app_filename>.sh <matlab_runtime_directory path>
he log file will generate properly.
Mathworks support is looking to this issue, trying to figure out why starting the app with a double click on the icon doesn't generate a log file. I'll post back here if they are able to figure it out.

Sign in to comment.

Accepted Answer

Michael
Michael on 16 Jul 2021
I got a response back from Mathworks Support about this. In short, as suspected, there is an issue with file permissions in Finder that doesn't allow the log file from being generated. As a work around, you can use diary.m in the application to write a file to a known and accessible file. I put this diary.m call in my applications startup function. Below is the response from Mathworks (thanks to Cam at Mathworks Support)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have found that this issue has to do with how the Finder application starts programs when you double click on them.
When using MATLAB Compiler, if the option is specified to create a log file then the log file will be created in the directory that the compiled application is started from. When we used the generated run script to start the program, this was the directory that the program was in.
When an application is started via Finder, this is not the case. From the limited information that I can find about how Finder works, the application is most likely started from the root directory of the file system: '/'. It is likely that the application does not have access to write in this location, so the log file is not created.
Unfortunately, the '-logfile' flag for the 'mcc' command does not allow us to specify the directory that the file should be placed in, only the name of the file. However, we can workaround this by using the 'diary' function.
The 'diary' function logs any output that would be shown in the Command Window to a file, similarly to how the '-logfile' option works with the 'mcc' command. The difference is that the 'diary' function allows us to specify the location of the file that is created.
To use this, you could simply add the command "diary('/Path/to/destination/log.txt')" to the startup function of your application. The default behavior of the 'diary' function is to append to the file if it already exists, so each time you run the application the log file would become larger.
If you would like a new file to be created for each run of the program, you could use something like the following:
dateString = datestr(clock);
logName = ['/Users/<username>/Desktop/log_' dateString '.txt'];
diary(logName);
By using this method, a new log file will be created for each run of the program, since the name of the file includes the current date and time.
You can find the documentation for the 'diary' function here:
I am going to go ahead and close this case for now, but if you have any additional questions related to this topic please respond to this email and I will be happy to re-open the case to assist you further.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!