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