Changeset 5071
- Timestamp:
- Sep 19, 2005, 2:31:22 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/sys/psTrace.c (modified) (14 diffs)
-
test/sys/tst_psTrace.c (modified) (4 diffs)
-
test/sys/verified/tst_psTrace.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psTrace.c
r4972 r5071 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-09- 08 00:27:50$11 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-09-20 00:31:22 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 54 54 55 55 static p_psComponent* cRoot = NULL; // The root of the trace component 56 static FILE *traceFP = NULL; // File destination for messages.56 // static FILE *traceFP = NULL; // File destination for messages. 57 57 static psBool traceTime = false; // Flag to include time info 58 58 static psBool traceHost = false; // Flag to include host info … … 60 60 static psBool traceName = false; // Flag to include name info 61 61 static psBool traceMsg = true; // Flag to include message info 62 //static int traceFD = 0; 62 static int traceFD = STDOUT_FILENO; // default value 63 63 64 64 static void componentFree(p_psComponent* comp); … … 259 259 if (cRoot == NULL) { 260 260 initTrace(); 261 }262 263 if (traceFP == NULL) {264 traceFP = stdout;265 261 } 266 262 … … 436 432 psS32 defLevel) 437 433 { 434 char line[1024]; 438 435 psS32 i = 0; 439 436 440 if (traceFP == NULL) {441 traceFP = stdout;442 }437 // XXX EAM : probably should just return if traceFD < 1 438 if (traceFD < 1) 439 return; 443 440 444 441 if (comp->name[0] == '\0') { … … 446 443 } else { 447 444 if (comp->level == PS_DEFAULT_TRACE_LEVEL) { 448 fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel); 445 // fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel); 446 sprintf(line,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel); 447 write (traceFD, line, strlen(line)); 449 448 } else { 450 fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level); 449 // fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level); 450 sprintf(line, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level); 451 write (traceFD, line, strlen(line)); 451 452 } 452 453 } … … 486 487 va_list ap) 487 488 { 488 char *fmt = NULL;489 // char *fmt = NULL; 489 490 // va_list ap; 490 491 static psS32 first = 1; // Flag for calling gethostname() … … 498 499 struct tm *utc = gmtime(&clock); // The current gm time. 499 500 500 if (traceFP == NULL) {501 traceFP = stdout;502 }501 // XXX EAM : fd < 1 does not print messages 502 if (traceFD < 1) 503 return; 503 504 504 505 if (NULL == comp) { … … 590 591 591 592 592 593 fputs(head, traceFP); 593 // fputs(head, traceFP); 594 write (traceFD, head, strlen(head)); 595 594 596 if (traceMsg) { 597 char line[1024]; 598 595 599 // The following functions get the variable list of parameters with 596 600 // which this function was called, and print them to the standard 597 601 // output. 598 fmt = va_arg(ap, char *);602 // fmt = va_arg(ap, char *); 599 603 600 604 // We indent each message one space for each level of the message. 601 605 for (i = 0; i < level; i++) { 602 606 // fprintf(traceFP, " "); 603 fprintf(traceFP, "%s", format); 607 // fprintf(traceFP, "%s", format); 608 // sprintf(line, "%s", format); 609 write (traceFD, " ", 1); 604 610 } 605 vfprintf(traceFP, fmt, ap); 611 // vfprintf(traceFP, fmt, ap); 612 vsprintf(line, format, ap); 613 write (traceFD, line, strlen(line)); 614 606 615 // vfprintf(traceFP, format, ap); 607 616 // va_end(ap); … … 609 618 char* msgPtr; 610 619 vsnprintf(msg,1024, format, ap); // create message 611 620 612 621 // detect multiple lines in message and indent each line by 4 spaces. 613 622 char* line = strtok_r(msg,"\n",&msgPtr); … … 618 627 */ 619 628 } else { 620 fputc('\n', traceFP); 629 // fputc('\n', traceFP); 630 write(traceFD, "\n", 1); 621 631 } 622 632 … … 647 657 va_list ap; 648 658 va_start(ap, format); 659 format = va_arg(ap, char *); 649 660 psTraceV(comp, level, format, ap); 650 661 va_end(ap); 651 fflush(traceFP); 662 // fflush(traceFP); 663 // XXX EAM : what is fd-appropriate equivalent? 652 664 } 653 665 … … 676 688 traceFP = fp; 677 689 */ 678 if (fd == -1) { 690 if (fd < 1) { 691 traceFD = 0; 679 692 return; 680 693 } 681 694 if (fd == 1) { 682 traceF P = stdout;695 traceFD = STDOUT_FILENO; 683 696 } else if (fd == 2) { 684 traceFP = stderr; 685 } else if (fd == 0) { 686 traceFP = stdin; 697 traceFD = STDERR_FILENO; 687 698 } else if (fd > 2) { 688 traceFP = fdopen(fd, "w"); 699 close (traceFD); 700 traceFD = fd; 689 701 } 690 702 } … … 692 704 int psTraceGetDestination() 693 705 { 694 int fd; 695 fd = fileno(traceFP); 696 return fd; 706 return traceFD; 697 707 } 698 708 -
trunk/psLib/test/sys/tst_psTrace.c
r4951 r5071 188 188 static psS32 testTrace04(void) 189 189 { 190 FILE *fp;191 190 int FD; 192 191 psS32 nb = 0; … … 194 193 // printf("\nFD = %d\n", FD); 195 194 // fp = fopen("tst_psTrace02_OUT", "w"); 196 fp = fdopen(FD, "w");197 195 for (nb = 0 ; nb<4;nb++) { 198 196 if (nb == 0) … … 203 201 psTraceSetDestination(2); 204 202 if (nb == 2) 205 psTraceSetDestination( -1); //NULL203 psTraceSetDestination(0); //NULL 206 204 if (nb == 3) 207 205 psTraceSetDestination(FD); … … 231 229 } 232 230 233 fclose(fp);234 231 close(FD); 235 232 -
trunk/psLib/test/sys/verified/tst_psTrace.stderr
r4547 r5071 64 64 (1) This message should be displayed (beefface) 65 65 (2) This message should be displayed (beefface) 66 (0) This message should be displayed (beefface)67 (1) This message should be displayed (beefface)68 (2) This message should be displayed (beefface)69 66 70 67 ---> TESTPOINT PASSED (psTrace{psTrace()} | tst_psTrace.c)
Note:
See TracChangeset
for help on using the changeset viewer.
