Create Diary in a function?
4 vues (au cours des 30 derniers jours)
Florian Rössing le 6 Mai 2022
I am currently working on a simulation project where I want progress logs to be written to a file, so I can inspect them later. I was using diary for this. However having the setup of diary in the main function look ugly and made it bulky, so I wanted to move all the setup and diary functionality to a seperate function alike this:
diaryfile = append(RunPath, 'log.txt');
if exist(diaryfile, 'file')
RAII.diary = onCleanup(@() diary('off'));
However as soon as the function finishes the diary falls out of scope and is closed.
Is there a way to pass the diary out of the function?