Customization of log file

4 次查看(过去 30 天)
Lorenzo Bernardi
Lorenzo Bernardi 2021-11-19
评论: Rik 2021-11-19
I need to execute a function saving a logfile.
More in detail, I need to add some custom logs into the diary logfile
Currently Im using the following instruction:
eval(['diary ', logfile])
%my function script
%... STEP 1
%... STEP 2
%... STEP3
% 0 (function end without error)
diary off
So, here after the following question:
  1. how add to the logfile created using the diary function some custom logs such as for example: STEP 1 completed, STEP 2 completed, STEP 3 Completed
  2. how capture the "0" end of running section, meaning that the function works without errors, and this value for closing my Logfile.
RESOLVED by using fopen, fprintf, and fclose for generating and append logs to my logfile.
I used a try - catch statment like following::
try
%
%DO SOMETHING
%
fprintf(fid, '%d\n', 0); %Right execution set = 0
catch ME
fprintf(fid, '%s\n', ME.identifier);
fprintf(fid, '%s\n', ME.message);
fprintf(fid, '%d\n', -1); %Error catched and appended to the logfile
end
  2 个评论
Rik
Rik 2021-11-19
Do you have to use a diary? Can't you just use fopen and fprintf (and fclose) to write to a log file?
I'm updating my functions on the FEX to allow exactly that: redirect errors and warnings to a log file instead of the command window.
Rik
Rik 2021-11-19
You should post your answer as an answer. Then you can accept your answer.
If you want I can post the code I use to redirect errors and warnings. Those two functions are intended to be drop in replacements for any calls to warning() and error().

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by