Repository navigation
Expand file tree
/
Copy pathaas_log.m
More file actions
109 lines (97 loc) · 3.37 KB
/
Copy pathaas_log.m
File metadata and controls
109 lines (97 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
% automatic analysis - log tool
% used to display messages
% if iserr is true, an error is generated
% function aas_log(aap,iserr,msg,style)
function aas_log(aap,iserr,msg,style)
global aa;
if ~isobject(aa) % aa is not running
clear global aa;
aa = aaClass('nopath','nogreet');
end
% in case msg is a String, convert it to char array
msg = convertStringsToChars(msg);
% figure out whether the caller is an engine (aaq_*)
ST = dbstack;
isEngine = numel(ST) > 1 && ~isempty(strfind(ST(2).name,'aaq'));
% aap defaults
if ~isstruct(aap)
aap.options.verbose = 2;
aap.options.email = '';
aap.gui_controls.usecolouroutput = false;
end
if ~isfield(aap.options,'verbose'), aap.options.verbose = 2; end
% don't attempt html tags if running outside of Matlab desktop
if ~aap.gui_controls.usecolouroutput
style='text';
elseif nargin < 4
if ~isempty(strfind(msg,'ERROR')) && isfield(aap.gui_controls.colours,'error'), style = aap.gui_controls.colours.error;
elseif ~isempty(strfind(msg,'WARNING')) && isfield(aap.gui_controls.colours,'warning'), style = aap.gui_controls.colours.warning;
elseif ~isempty(strfind(msg,'INFO')) && isfield(aap.gui_controls.colours,'info'), style = aap.gui_controls.colours.info;
else style='text';
end
end
if iserr % errors
if aap.options.verbose > 0
logitem('\n\n**** automatic analysis failed - see reason and line numbers below\n','red');
% suppress e-mail from low level functions in case of cluster computing
if ~isempty(aap.options.email) && (strcmp(aap.options.wheretoprocess,'localsingle') || isEngine)
% In case the server is broken...
try
aas_finishedMail(aap, msg)
catch
end
end
logitem([msg '\n'],style);
logitem('for help, see the ')
logitem(sprintf('<a href="%s">aa wiki</a>\n',aa.aawiki),[0 0 1])
end
global aaworker
if (isfield(aaworker,'errorflagname'))
fid=fopen(aaworker.errorflagname,'w');
fprintf(fid,'[%d.%02d.%02d %02d:%02d:%02d] ',round(clock));
fclose(fid);
end
if isfield(aap,'internal') && isfield(aap.internal,'pwd') && exist(aap.internal.pwd,'dir')
cd(aap.internal.pwd)
end
% undocumented, for devel only
if aap.options.verbose ~= -1
error('aa:internal','aa error:\n%s\n','see above (or set aap.options.verbose)')
end
else % warnings
if aap.options.verbose == 2, logitem([msg '\n'],style); end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function logitem(msg,style)
global aaparallel;
if nargin < 2
style='text';
end;
% output to screen
if ~isempty(strfind(msg,'parallel-manage-workers'))
pmw_log.msg=msg;
pmw_log.when=clock;
if ~isfield(aaparallel,'manage_workers_log')
aaparallel.manage_workers_log=pmw_log;
else
aaparallel.manage_workers_log(end+1)=pmw_log;
end;
else
% no colours when deployed... (or when on command line)
if isdeployed || ~usejava('desktop') || ~exist('cprintf','file')
fprintf(msg);
else
cprintf(style,msg);
end;
end;
% and to worker file?
global aaworker
if isfield(aaworker,'logname')
fid=fopen(aaworker.logname,'a');
fprintf(fid,'[%d.%02d.%02d %02d:%02d:%02d] ',round(clock));
fprintf(fid,msg);
fclose(fid);
if isfield(aaworker,'master'), aas_propagateto(aaworker.master.hostname,aaworker.logname); end
end;
end