Changeset 4951 for trunk/psLib/src/sys
- Timestamp:
- Sep 6, 2005, 2:15:51 PM (21 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 4 edited
-
psLogMsg.c (modified) (4 diffs)
-
psLogMsg.h (modified) (2 diffs)
-
psTrace.c (modified) (10 diffs)
-
psTrace.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psLogMsg.c
r4540 r4951 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.4 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-0 7-12 19:12:01$14 * @version $Revision: 1.49 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-09-07 00:15:48 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 37 37 #include <time.h> 38 38 #include <unistd.h> 39 #include <fcntl.h> 39 40 40 41 #include "psLogMsg.h" … … 87 88 An psBool: TRUE if successful. 88 89 *****************************************************************************/ 89 bool psLogSetDestination( const char *dest)90 bool psLogSetDestination(int fd) 90 91 { 91 char protocol[5]; 92 char location[257]; 93 92 // char protocol[5]; 93 // char location[257]; 94 // char dest[257]; 95 FILE *fp; 94 96 // if logDest has not been initialized, do so before using it 95 97 if (logDest == (FILE *) 1) { … … 97 99 } 98 100 99 if (dest == NULL || strcmp(dest, "none") == 0) { 101 if ( fd == 1 ) { 102 // fp = stdout; 100 103 if (logDest != NULL && logDest != stderr && logDest != stdout) { 101 104 fclose(logDest); 102 105 } 106 logDest = stdout; 107 } else if (fd == 2) { 108 // fp = stderr; 109 if (logDest != NULL && logDest != stderr && logDest != stdout) { 110 fclose(logDest); 111 } 112 logDest = stderr; 113 } else if (fd == 0) { 114 // fp = NULL; 115 if (logDest != NULL && logDest != stderr && logDest != stdout) { 116 fclose(logDest); 117 } 103 118 logDest = NULL; 104 119 return true; 105 } 106 107 if (sscanf(dest, "%4s:%256s", protocol, location) < 2) { 108 psError(PS_ERR_LOCATION_INVALID, true, 109 PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED, 110 dest); 111 return false; 112 } 113 114 if (strcmp(protocol, "dest") == 0) { 115 if (strcmp(location, "stderr") == 0) { 120 } else if (fd > 2) { 121 if (logDest != NULL && logDest != stderr && logDest != stdout) { 122 fclose(logDest); 123 } 124 fp = fdopen(fd, "w"); 125 logDest = fp; 126 // fclose(fp); 127 return true; 128 } 129 130 /* 131 if (dest == NULL || strcmp(dest, "none") == 0) { 116 132 if (logDest != NULL && logDest != stderr && logDest != stdout) { 117 133 fclose(logDest); 118 134 } 119 logDest = stderr;135 logDest = NULL; 120 136 return true; 121 137 } 122 if (strcmp(location, "stdout") == 0) { 138 if (sscanf(dest, "%4s:%256s", protocol, location) < 2) { 139 psError(PS_ERR_LOCATION_INVALID, true, 140 PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED, 141 dest); 142 return false; 143 } 144 */ 145 /* 146 147 if (strcmp(protocol, "dest") == 0) { 148 if (strcmp(location, "stderr") == 0) { 149 if (logDest != NULL && logDest != stderr && logDest != stdout) { 150 fclose(logDest); 151 } 152 logDest = stderr; 153 return true; 154 } 155 if (strcmp(location, "stdout") == 0) { 156 if (logDest != NULL && logDest != stderr && logDest != stdout) { 157 fclose(logDest); 158 } 159 logDest = stdout; 160 return true; 161 } 162 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID, 163 location); 164 return 1; 165 } else if (strcmp(protocol, "file") == 0) { 166 FILE *file = fopen(location, "w"); 167 168 if (file == NULL) { 169 psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED, 170 location); 171 return false; 172 } 123 173 if (logDest != NULL && logDest != stderr && logDest != stdout) { 124 174 fclose(logDest); 125 175 } 126 logDest = stdout;176 logDest = file; 127 177 return true; 128 178 } 129 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID, 130 location); 131 return 1; 132 } else if (strcmp(protocol, "file") == 0) { 133 FILE *file = fopen(location, "w"); 134 135 if (file == NULL) { 136 psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED, 137 location); 138 return false; 139 } 140 if (logDest != NULL && logDest != stderr && logDest != stdout) { 141 fclose(logDest); 142 } 143 logDest = file; 144 return true; 145 } 146 147 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_UNSUPPORTED_PROTOCOL, 148 protocol); 149 return false; 179 */ 180 return true; 181 150 182 } 151 183 -
trunk/psLib/src/sys/psLogMsg.h
r4556 r4951 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $14 * @date $Date: 2005-0 7-15 02:33:54$13 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-09-07 00:15:48 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 */ 34 34 bool psLogSetDestination( 35 const char *dest///< Specifies where to send messages.35 int fd ///< Specifies where to send messages. 36 36 ); 37 37 -
trunk/psLib/src/sys/psTrace.c
r4944 r4951 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.5 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-09-0 2 21:32:06$11 * @version $Revision: 1.57 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-09-07 00:15:48 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 245 245 zero 246 246 *****************************************************************************/ 247 psBoolpsTraceSetLevel(const char *comp, // component of interest248 int level) // desired trace level247 int psTraceSetLevel(const char *comp, // component of interest 248 int level) // desired trace level 249 249 { 250 250 char *compName = NULL; 251 int prevLevel = -1; 251 252 252 253 // If the root component tree does not exist, then initialize it. … … 267 268 compName = (char *) comp; 268 269 } 269 270 prevLevel = psTraceGetLevel(compName); 270 271 // Add the new component to the component tree. 271 272 if ( !componentAdd(compName, level) ) { … … 278 279 psFree(compName); 279 280 } 280 return false; 281 // return false; 282 return -1; 281 283 } 282 284 … … 285 287 } 286 288 287 return true; 289 // return true; 290 return prevLevel; 288 291 } 289 292 … … 489 492 void p_psTrace(const char *comp, // component being traced 490 493 int level, // desired trace level 494 const char *format, 491 495 ...) // arguments 492 496 { … … 508 512 // of it's associatedcomponent. 509 513 if (level <= psTraceGetLevel(comp)) { 510 va_start(ap, level);514 va_start(ap, format); 511 515 512 516 // The following functions get the variable list of parameters with … … 517 521 // We indent each message one space for each level of the message. 518 522 for (i = 0; i < level; i++) { 519 fprintf(traceFP, " "); 523 // fprintf(traceFP, " "); 524 fprintf(traceFP, "%s", format); 520 525 } 521 526 vfprintf(traceFP, fmt, ap); 527 // vfprintf(traceFP, format, ap); 522 528 va_end(ap); 523 529 } … … 532 538 /* 533 539 bool special; 534 540 535 541 // XXX EAM perhaps return an error? 536 542 if (fp == NULL) { 537 543 return; 538 544 } 539 545 540 546 // cannot close traceFP if one of the special FILE ptrs 541 547 special = (traceFP == NULL); … … 543 549 special |= (traceFP == stdout); 544 550 special |= (traceFP == stderr); 545 551 546 552 if (!special) { 547 553 fclose (traceFP); -
trunk/psLib/src/sys/psTrace.h
r4944 r4951 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.3 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-09-0 2 21:32:06$11 * @version $Revision: 1.37 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-09-07 00:15:48 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 64 64 const char *facil, ///< facilty of interest 65 65 int level, ///< desired trace level 66 const char *format, ///< printf-style format command 66 67 ... ///< trace message arguments 67 68 ); … … 72 73 const char *facil, ///< facilty of interest 73 74 psS32 myLevel, ///< desired trace level 75 const char *format, ///< printf-style format command 74 76 ... ///< trace message arguments 75 77 ); … … 83 85 /** Set trace level 84 86 * 85 * @return psBool: True if successful, otherwise false87 * @return int: The previous level. 86 88 */ 87 psBoolpsTraceSetLevel(89 int psTraceSetLevel( 88 90 const char *facil, ///< facilty of interest 89 91 int level ///< desired trace level
Note:
See TracChangeset
for help on using the changeset viewer.
