SASUnit Examples  Version 1.5.0
_reportloghtml.sas
Go to the documentation of this file.
1 
33 %MACRO _reportLogHTML(i_log =
34  ,i_title = SAS-Log
35  ,o_html = 0
36  ,r_rc = logrc
37  );
38 
39  %LOCAL
40  l_macname
41  l_log
42  l_html
43  l_error_count
44  l_warning_count
45  l_curError
46  l_curWarning
47  l_sIgnoreLogMessage01
48  ;
49 
50  %LET l_macname=&sysmacroname;
51  %LET l_log = &i_log;
52  %LET l_html = &o_html;
53 
54  %LET &r_rc=3;
55 
56  /*erster Log-Durchlauf zur Bestimmung von Fehler- und Warnungsanzahl*/
57  %_checkLog(i_logfile = &l_log
58  ,i_error = &g_error.
59  ,i_warning = &g_warning.
60  ,r_errors = l_error_count
61  ,r_warnings = l_warning_count
62  );
63 
64  %IF %_handleError(&l_macname
65  ,LogNotFound
66  ,&syserr. NE 0
67  ,Fehler beim Zugriff auf den Log
68  ,i_verbose=&g_verbose.
69  )
70  %THEN %GOTO errexit;
71 
72  /* TODO consolidate all logscan logic into datastep functions and use them throughout the project.
73  The SAS option CMPLIB must then be set for all sessions to use these functions.
74  */
75  %LET l_sIgnoreLogMessage01 = %STR(ERROR: Errors printed on page);
76 
77  DATA _NULL_;
78 
79  INFILE "&l_log" END=eof TRUNCOVER;
80  FILE "&l_html";
81  INPUT logline $char255.;
82 
83  ATTRIB
84  _errorPatternId LENGTH = 8
85  _ignoreErrPatternId LENGTH = 8
86  _warningPatternId LENGTH = 8
87  error_count LENGTH = 8
88  warning_count LENGTH = 8
89  ;
90  RETAIN
91  _errorPatternId 0
92  _ignoreErrPatternId 0
93  _warningPatternId 0
94  error_count 0
95  warning_count 0
96  ;
97 
98  /* Undo macro quoting: convert 'CAN' to "/", 'SYN' to "-" and 'SO' to ";"
99  as well as delete 'BS', 'ACK', 'SOH' 'FF' and 'STX' */
100  logline = TRANSLATE(logline, "2F"x, "18"x);
101  logline = TRANSLATE(logline, "3B"x, "0E"x);
102  logline = TRANSLATE(logline, "2D"x, "17"x);
103  logline = transtrn(logline, "08"x, trimn(''));
104  logline = transtrn(logline, "06"x, trimn(''));
105  logline = transtrn(logline, "01"x, trimn(''));
106  logline = transtrn(logline, "02"x, trimn(''));
107  logline = transtrn(logline, "0C"x, trimn(''));
108 
109  IF _n_=1 THEN DO;
110 
111  _errorPatternId = prxparse("/^%UPCASE(&g_error.)[: ]/");
112  _warningPatternId = prxparse("/^%UPCASE(&g_warning.)[: ]/");
113  _ignoreErrPatternId = prxparse("/^&l_sIgnoreLogMessage01./");
114 
115  /*HTML-Header*/
116  PUT '<html>';
117  PUT '<head>';
118  PUT '<meta http-equiv="Content-Language" content="de">';
119  PUT '<meta name="GENERATOR" content="SAS &sysver">';
120  PUT '<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">';
121  PUT "<title>&i_title</title>";
122  PUT '</head>';
123  /*HTML-Body*/
124  PUT '<body>';
125  /*Ausgabe einer Seiten-Kopfzeile mit verlinkter Übersicht zu Fehler- und Warnmeldungen*/
126  PUT '<p style="background-color:#EAEAEA; font-family:Fixedsys,Courier,monospace">';
127  PUT "&g_nls_reportLog_001: &l_error_count. ";
128  %DO l_curError = 1 %TO &l_error_count.;
129  IF &l_curError=1 THEN PUT '==>';
130  PUT '<a href="#error' "%sysfunc(putn(&l_curError,z3.))" '">' "&l_curError." '</a>';
131  %END;
132  PUT '<br>';
133  PUT "&g_nls_reportLog_002: &l_warning_count. ";
134  %DO l_curWarning = 1 %TO &l_warning_count.;
135  IF &l_curWarning=1 THEN PUT '==>';
136  PUT '<a href="#warning' "%sysfunc(putn(&l_curWarning,z3.))" '">' "&l_curWarning." '</a>';
137  %END;
138  PUT '<br>';
139  PUT '</p>';
140  PUT '<pre>';
141  END;
142 
143  /*Ausgabe der Log-Zeilen. Fehler- und Warnmeldungen werden farbig markiert und verlinkt*/
144  IF prxmatch (_errorPatternId, logline)
145  AND (NOT prxmatch (_ignoreErrPatternId, logline)) THEN DO;
146  error_count+1;
147  PUT '<span style="color:#FF0000">' @;
148  PUT '<a name="error' error_count z3. '">' @;
149  l = length(logline);
150  PUT logline $varying255. l @;
151  PUT '</a>'@;
152  PUT '</span>';
153  END;
154  ELSE IF prxmatch (_warningPatternId, logline) THEN DO;
155  warning_count+1;
156  PUT '<span style="color:#FF8040">' @;
157  PUT '<a name="warning' warning_count z3. '">' @;
158  l = length(logline);
159  PUT logline $varying255. l @;
160  PUT '</a>' @;
161  PUT '</span>';
162  END;
163  ELSE DO;
164  /*Ersetzung der Zeichen <, > mit entsprechenden HTML-Codes*/
165  DO WHILE (index(logline, '<') > 0);
166  textpos = index(logline, '<');
167  IF textpos NE 1 THEN
168  newlogline = substr(logline, 1, (textpos - 1)) ||'&lt;'||substr(logline, (textpos +length('<')));
169  ELSE
170  newlogline = '&lt;'||substr(logline, (textpos + length('<')));
171  logline = newlogline;
172  END;
173 
174  DO WHILE (index(logline, '>') > 0);
175  textpos = index(logline, '>');
176  IF textpos NE 1 THEN
177  newlogline = substr(logline, 1, (textpos - 1)) ||'&gt;'||substr(logline, (textpos +length('>')));
178  ELSE
179  newlogline = '&gt;'||substr(logline, (textpos + length('>')));
180  logline = newlogline;
181  END;
182  /*Ausgabe in HTML-Datei*/
183  l = length(logline);
184  PUT logline $varying255. l;
185  END;
186 
187  IF eof THEN DO;
188  PUT '</pre>';
189  PUT '</body>';
190  PUT '</html>';
191  END;
192  RUN;
193 
194  %IF %_handleError(&l_macname
195  ,ErrorWriteHTML
196  ,&syserr. NE 0
197  ,Fehler beim Schreiben der HTML-Datei
198  ,i_verbose=&g_verbose.
199  )
200  %THEN %GOTO errexit;
201 
202  %IF &l_error_count > 0 %THEN %LET &r_rc = 2;
203  %ELSE %IF &l_warning_count > 0 %THEN %LET &r_rc = 1;
204  %ELSE %LET &r_rc=0;
205 
206  %GOTO exit;
207 %errexit:
208 %exit:
209 %MEND _reportLogHTML;
210