12 #define MAX_LOGFILES 10
15 #define DATA_1 "/online/tonko/log_content_old.html"
16 #define DATA_2 "/online/tonko/log_content.html"
17 #define TOUCH "/online/tonko/log_touch.html"
20 int parseLog(
char *b, u_int file, u_int line) ;
23 static char buff[1024] ;
24 static struct stat statb ;
27 #warning "PROJDIR not defined! Assuming /RTS"
28 #define PROJDIR "/RTS"
34 static char logfiles[MAX_LOGFILES][128] = {
35 PROJDIR
"/log/rts.log"LOG_SUFFIX,
36 PROJDIR
"/log/trigger.log"LOG_SUFFIX,
37 PROJDIR
"/log/evp.log"LOG_SUFFIX,
38 PROJDIR
"/log/det.log"LOG_SUFFIX,
39 PROJDIR
"/log/daq.log"LOG_SUFFIX,
40 PROJDIR
"/log/tpx.log"LOG_SUFFIX,
41 PROJDIR
"/log/esb.log"LOG_SUFFIX,
47 static FILE *files[MAX_LOGFILES] ;
49 static int oldsizes[MAX_LOGFILES] ;
52 static char data_preamble[] = {
" \
53 <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> \
56 <link rel=\"stylesheet\" type=\"text/css\" href=\"daq.css\"> \
57 <title>STAR DAQ Logging</title> \
64 static struct logline {
84 } loglines[LOGLINES] ;
86 int last_logline = 0 ;
89 int main(
int argc,
char *argv[])
94 int data_in, new_lines ;
96 u_int lines[MAX_LOGFILES] ;
100 for(i=0;i<MAX_LOGFILES;i++) {
101 printf(
"%3d: %d %c -%s-\n",i,logfiles[i][0],logfiles[i][0],logfiles[i]) ;
109 FILE *ff = fopen(TOUCH,
"w") ;
110 fprintf(ff,
"%u\n",(u_int)time(NULL)) ;
113 while(logfiles[i][0] != 0) {
115 files[i] = fopen(logfiles[i],
"r") ;
117 if(files[i] == NULL) {
118 perror(logfiles[i]) ;
126 memset(lines,0,
sizeof(lines)) ;
132 u_int last_delta = time(NULL) - last_flush ;
136 for(i=0;i<MAX_LOGFILES;i++) {
138 if(logfiles[i][0]==0) continue ;
144 fret = fgets(buff,
sizeof(buff),files[i]) ;
148 perror(logfiles[i]) ;
154 ret = stat(logfiles[i],&statb) ;
156 perror(logfiles[i]) ;
161 if(statb.st_size < oldsizes[i]) {
164 files[i] = fopen(logfiles[i],
"r") ;
170 oldsizes[i] = statb.st_size ;
178 if((strstr(buff,
"CRITICAL") != NULL) ||\
179 (strstr(buff,
"OPERATOR") != NULL) ||\
180 (strstr(buff,
"CAUTION") != NULL)) {
182 parseLog(buff,i,lines[i]) ;
193 if((last_delta >= 60) || (new_lines && (last_delta >= 5))) {
194 last_flush = time(NULL) ;
197 printf(
"Dumping %d lines\n",new_lines) ;
202 printf(
"No data...\n") ;
206 static u_int tot_data ;
207 tot_data += data_in ;
209 if((tot_data % 10000)==0) {
210 printf(
"read %d lines\n",tot_data) ;
221 int parseLog(
char *b, u_int file, u_int seq)
226 static char task[128] ;
227 static char line[128] ;
231 u_int min_sec = 0xffffffff ;
233 for(i=0;i<LOGLINES;i++) {
234 if(loglines[i].sec == 0) {
239 if(loglines[i].sec <= min_sec) {
240 min_sec = loglines[i].sec ;
246 loglines[use].repeat = 1 ;
255 loglines[use].node[cou++] = *b++ ;
257 loglines[use].node[cou] = 0 ;
259 while(*(++b) ==
' ') ;
272 loglines[use].day = atoi(day) ;
290 loglines[use].sev[cou++] = *b++ ;
292 loglines[use].sev[cou] = 0 ;
300 loglines[use].src[cou++] = *b++ ;
302 loglines[use].src[cou] = 0 ;
312 loglines[use].line = atoi(line) ;
316 *(b+strlen(b)-1) = 0 ;
318 strncpy(loglines[use].tm,tm,
sizeof(loglines[use].tm)-1) ;
320 char itm[
sizeof(tm)] ;
323 for(cou=0;cou<strlen(tm);cou++) {
324 if(itm[cou] ==
':') itm[cou] = 0 ;
328 loglines[use].sec = loglines[use].day*24*3600 + atoi(itm)*3600 + atoi(itm+3)*60 + atoi(itm+6) ;
333 if((task[1] ==
'R') && (task[2] ==
'B') && (task[5] ==
'_') && (task[7] ==
']')) {
334 strncpy(rb+1,task+1,6) ;
340 the_task = &task[9] ;
341 if((task[9] ==
'0') && (task[10]==
'x')) {
342 *(task+strlen(task)-1)=0 ;
343 while(*the_task++ !=
'(') ;
351 *(the_task + strlen(the_task) -1) = 0 ;
354 if(strlen(the_task) == 0) {
355 strcpy(the_task,
"???") ;
358 strncpy(loglines[use].task,the_task,
sizeof(loglines[use].task)-1) ;
359 strncpy(loglines[use].rb,rb,
sizeof(loglines[use].rb)-1) ;
360 strncpy(loglines[use].msg,b,
sizeof(loglines[use].msg)-1) ;
362 printf(
"Adding %d, last %d: file %d, line %d....\n",use,last_logline,file,seq) ;
364 loglines[use].seq = seq ;
365 loglines[use].file = file ;
367 for(i=0;i<LOGLINES;i++) {
368 if(i==use) continue ;
369 if(loglines[i].sec == 0) continue ;
371 if(loglines[i].line == loglines[use].line) {
372 if(loglines[i].file == loglines[use].file) {
373 if(loglines[i].sec == loglines[use].sec) {
374 if(strcmp(loglines[i].node,loglines[use].node)==0) {
375 if(strcmp(loglines[i].src,loglines[use].src) == 0) {
376 if(strcmp(loglines[i].task,loglines[use].task) == 0) {
377 loglines[use].repeat = loglines[i].repeat + 1 ;
378 loglines[i].sec = 0 ;
389 int compare(
const void *s1,
const void *s2)
391 struct logline *l1 = (
struct logline *)s1 ;
392 struct logline *l2 = (
struct logline *)s2 ;
394 if(l1->sec < l2->sec)
return 1 ;
395 if(l1->sec > l2->sec)
return -1 ;
397 if(l1->file == l2->file) {
398 if(l1->seq < l2->seq)
return 1 ;
399 if(l1->seq > l2->seq)
return -1 ;
404 if(l1->file < l2->file)
return 1 ;
405 if(l1->file > l2->file)
return -1 ;
416 time_t now = time(NULL) ;
417 struct tm *stm = localtime(&now) ;
420 FILE *o = fopen(DATA_1,
"w") ;
426 fprintf(o,
"%s\n",data_preamble) ;
428 fprintf(o,
"<table width=100%% border=1 cellspacing=0>\n") ;
429 fprintf(o,
"<tr %s><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
431 "Time",
"#",
"Node",
"Severity",
"Task",
"Source#line",
"Msg") ;
436 int sec = stm->tm_yday*24*3600 + stm->tm_hour*3600 + stm->tm_min*60 + stm->tm_sec ;
439 qsort(loglines,LOGLINES,
sizeof(loglines[0]),compare) ;
442 for(i=0;i<LOGLINES;i++) {
443 if(loglines[i].sec == 0) continue ;
445 int delta = sec - loglines[i].sec ;
450 if(strncmp(loglines[i].sev,
"CRIT",4)==0) color =
"style=color:#FF3333" ;
451 else if(strncmp(loglines[i].sev,
"CAUT",4)==0) color =
"style=color:#FF33FF" ;
452 else if(strncmp(loglines[i].sev,
"OPER",4)==0) color =
"style=color:#3333FF" ;
453 else color =
"style=color:#333333" ;
457 if(strncmp(loglines[i].sev,
"CRIT",4)==0) color =
"style=color:#FF0000;font-weight:bold" ;
458 else if(strncmp(loglines[i].sev,
"CAUT",4)==0) color =
"style=color:#FF00FF;font-weight:bold" ;
459 else if(strncmp(loglines[i].sev,
"OPER",4)==0) color =
"style=color:#0000FF;font-weight:bold" ;
460 else color =
"style=color:#000000;font-weight:bold" ;
464 fprintf(o,
"<tr %s><td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s%s</td><td>%s#%d</td><td>%s</td></tr>\n",
466 loglines[i].tm,loglines[i].repeat,
467 loglines[i].node,loglines[i].sev,loglines[i].task,loglines[i].rb,loglines[i].src,loglines[i].line,loglines[i].msg) ;
473 fprintf(o,
"</table>\n") ;
475 fprintf(o,
"\n</body></html>\n") ;
478 rename(DATA_1,DATA_2) ;
482 struct utimbuf utim ;
486 utime(DATA_2,&utim) ;