Compiled application does not write to diary log file

조회 수: 21 (최근 30일)
MC
MC 2020년 1월 16일
댓글: Dani 2020년 6월 19일
Hi all,
I have created a project using app designer and a number of functions. To keep track of how the calculation routes through the various functions I save comments in a log file using the diary() function and many fprintf() functions (see simplified example code below). This all works perfectly when run through matlab.
However, when I run a compiled version of the project, the log file is completely empty, even though the log file itself is created. (other files are also created/saved correctly).
I assume it's because there is no command window... for fprintf() to write to...? The same happens on my colleagues system.
Is there a way around this? Or do I need to write a dedicated logging function?
TIA, Mark.
R2019b
function mlappGUI()
main()
end
function main()
diary('c:\MatLab\logFile.log') %starts the log file
sub1()
sub2()
diary off
end
function sub1()
fprintf('subFunction1 : log file comment\n');
end
function sub2()
fprintf('subFunction2 : log file comment\n');
end
  댓글 수: 1
Dani
Dani 2020년 6월 19일
If I compile your example (mcc -e mlappGUI.m) und run the exe then I do get the logfile with all its entries. This is with 2020a.
But I have come across this problem before. I was relying on diary for logging warnings and errors in my deployed applications (yes, lazy, but efficient, saves you adding endless try-catch statements) and with the introduction of 2019b it stopped working. The problem was that it did not stop to work entierly, so simple test cases worked for me but my full application it did not. Difficult to debug. So, I'm not sure if your test script is one of the simple cases or if in 2020a this started working properly again.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 1월 16일
I think you are right. The cause is that there is no Command Window in your compiled app.
I would suggest writing to a specific file. Use fid=fopen() to create a FID and then fprintf(fid,'log text')
You can switch to Command Window when forcing fid to be 1.
fprintf(1,'abc\n') is the same as display('abc')
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2020년 1월 17일
When you debug during development, force logID to be 1 somewhere then it will print to the Command Window. Run diary() outside of your app to save the log into a file.
MC
MC 2020년 1월 17일
Good tip. thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by