Changeset 4951
- Timestamp:
- Sep 6, 2005, 2:15:51 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 7 edited
-
src/sys/psLogMsg.c (modified) (4 diffs)
-
src/sys/psLogMsg.h (modified) (2 diffs)
-
src/sys/psTrace.c (modified) (10 diffs)
-
src/sys/psTrace.h (modified) (4 diffs)
-
test/math/tst_psRandom.c (modified) (4 diffs)
-
test/sys/tst_psLogMsg.c (modified) (5 diffs)
-
test/sys/tst_psTrace.c (modified) (2 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 -
trunk/psLib/test/math/tst_psRandom.c
r4859 r4951 19 19 #include <stdio.h> 20 20 #include <math.h> 21 #include <fcntl.h> 22 #include <unistd.h> 21 23 #include "pslib_strict.h" 22 24 #include "psTest.h" … … 80 82 81 83 // Valid type allocation with seed equal to zero 82 psLogSetDestination("file:seed_msglog1.txt"); 84 int fd1 = creat("seed_msglog1.txt", 0666); 85 // psLogSetDestination("file:seed_msglog1.txt"); 86 psLogSetDestination(fd1); 83 87 myRNG = psRandomAlloc(PS_RANDOM_TAUS, 0); 84 psLogSetDestination("dest:stderr"); 88 // psLogSetDestination("dest:stderr"); 89 psLogSetDestination(2); 85 90 if (myRNG == NULL) { 86 91 psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure"); … … 107 112 return 6; 108 113 } 114 close(fd1); 109 115 psFree(myRNG); 110 116 … … 291 297 psRandom *myRNG1 = NULL; 292 298 myRNG1 = psRandomAlloc(PS_RANDOM_TAUS, SEED); 293 psLogSetDestination("file:seed_msglog2.txt"); 299 // psLogSetDestination("dest:stderr"); 300 psLogSetDestination(0); 294 301 psRandomReset(myRNG1,0); 295 psLogSetDestination("dest:stderr"); 302 // psLogSetDestination("dest:stderr"); 303 psLogSetDestination(2); 296 304 psFree(myRNG1); 297 305 -
trunk/psLib/test/sys/tst_psLogMsg.c
r4547 r4951 7 7 #include "pslib_strict.h" 8 8 #include "psTest.h" 9 #include <unistd.h> 10 #include <fcntl.h> 9 11 10 12 static psS32 testLogMsg00(); … … 176 178 { 177 179 psS32 i = 0; 178 FILE* file; 179 char line[256]; 180 // FILE* file; 181 int fd; 182 // char line[256]; 180 183 181 184 printf("--------------- psLogSetDestination(PS_LOG_NONE) ----------------\n"); 182 psLogSetDestination("none"); 185 // psLogSetDestination("none"); 186 psLogSetDestination(0); 183 187 for (i=0;i<10;i++) { 184 188 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); … … 186 190 187 191 printf("------------- psLogSetDestination(PS_LOG_TO_STDERR) -------------\n"); 188 psLogSetDestination("dest:stderr"); 192 // psLogSetDestination("dest:stderr"); 193 psLogSetDestination(2); 189 194 for (i=0;i<10;i++) { 190 195 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); … … 192 197 193 198 printf("------------- psLogSetDestination(PS_LOG_TO_STDOUT) -------------\n"); 194 psLogSetDestination("dest:stdout"); 195 for (i=0;i<10;i++) { 196 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 197 } 199 // psLogSetDestination("dest:stdout"); 200 psLogSetDestination(1); 201 for (i=0;i<10;i++) { 202 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 203 } 204 198 205 printf("--------------- psLogSetDestination(""file:log.txt"") ---------------\n"); 199 psLogSetDestination("file:log.txt"); 200 for (i=0;i<10;i++) { 201 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 202 } 203 204 psLogSetDestination("none"); 206 fd = creat("log.txt", 0666); 207 // psLogSetDestination("file:log.txt"); 208 psLogSetDestination(fd); 209 for (i=0;i<10;i++) { 210 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 211 } 212 213 214 // psLogSetDestination("none"); 215 FILE *file; 216 char line[257]; 217 // psLogSetDestination(-1); 218 psLogSetDestination(0); 205 219 printf("--------------------- The Contents of log.txt -------------------\n"); 206 220 file = fopen("log.txt","r"); … … 209 223 } 210 224 fclose(file); 211 225 close(fd); 226 227 int fd2 = creat("/eva/log.txt", 0666); 212 228 printf("--------------- psLogSetDestination(""file:/eva/log.txt"") ----------\n"); 213 psLogSetDestination("file:/eva/log.txt"); 229 // psLogSetDestination("file:/eva/log.txt"); 230 psLogSetDestination(fd2); 214 231 for ( i=0;i<10;i++) { 215 232 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 216 233 } 217 218 return 0; 219 } 234 close(fd2); 235 236 return 0; 237 } -
trunk/psLib/test/sys/tst_psTrace.c
r4944 r4951 103 103 (void)psTraceSetLevel(".A.B.C.D.E", 5); 104 104 105 psTrace(".A.C.D.C",1," You should not see this.\n");106 psTrace(".A.B.C.D.E",2," You should see this.\n");107 psTrace(".A.B.C.D.E.F",3," You should see this too.\n");105 psTrace(".A.C.D.C",1," ","You should not see this.\n"); 106 psTrace(".A.B.C.D.E",2," ","You should see this.\n"); 107 psTrace(".A.B.C.D.E.F",3," ","You should see this too.\n"); 108 108 109 109 psTracePrintLevels(); … … 208 208 209 209 (void)psTraceSetLevel(".", 4); 210 psTrace(".", 5, " (0) This message should not be displayed (%x)\n",210 psTrace(".", 5, " ", "(0) This message should not be displayed (%x)\n", 211 211 0xbeefface); 212 212 (void)psTraceSetLevel(".", 7); 213 psTrace(".", 5, " (0) This message should be displayed (%x)\n",213 psTrace(".", 5, " ", "(0) This message should be displayed (%x)\n", 214 214 0xbeefface); 215 215 216 216 (void)psTraceSetLevel(".a", 4); 217 psTrace(".a", 5, " (1) This message should not be displayed (%x)\n",217 psTrace(".a", 5, " ", "(1) This message should not be displayed (%x)\n", 218 218 0xbeefface); 219 219 (void)psTraceSetLevel(".a", 7); 220 psTrace(".a", 5, " (1) This message should be displayed (%x)\n",220 psTrace(".a", 5, " ", "(1) This message should be displayed (%x)\n", 221 221 0xbeefface); 222 222 223 223 224 224 (void)psTraceSetLevel(".a.b", 4); 225 psTrace(".a.b", 5, " (2) This message should not be displayed (%x)\n",225 psTrace(".a.b", 5, " ", "(2) This message should not be displayed (%x)\n", 226 226 0xbeefface); 227 227 (void)psTraceSetLevel(".a.b", 7); 228 psTrace(".a.b", 5, " (2) This message should be displayed (%x)\n",228 psTrace(".a.b", 5, " ", "(2) This message should be displayed (%x)\n", 229 229 0xbeefface); 230 230
Note:
See TracChangeset
for help on using the changeset viewer.
