Changeset 4979
- Timestamp:
- Sep 8, 2005, 3:11:23 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 6 edited
-
src/sys/psLogMsg.c (modified) (6 diffs)
-
src/sys/psLogMsg.h (modified) (2 diffs)
-
src/types/psMetadataConfig.c (modified) (1 diff)
-
test/sys/tst_psLogMsg.c (modified) (3 diffs)
-
test/sys/verified/tst_psLogMsg.stderr (modified) (1 diff)
-
test/sys/verified/tst_psLogMsg.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psLogMsg.c
r4952 r4979 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.5 0$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-09-0 7 00:36:12 $14 * @version $Revision: 1.51 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-09-09 01:11:22 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 90 90 bool psLogSetDestination(int fd) 91 91 { 92 // char protocol[5];93 // char location[257];94 // char dest[257];95 92 FILE *fp; 96 93 // if logDest has not been initialized, do so before using it … … 98 95 logDest = stderr; 99 96 } 97 if (fd == -1) 98 return false; 100 99 101 100 if ( fd == 1 ) { … … 117 116 } 118 117 logDest = NULL; 119 return true;118 // return true; 120 119 } else if (fd > 2) { 121 120 if (logDest != NULL && logDest != stderr && logDest != stdout) { … … 125 124 logDest = fp; 126 125 // fclose(fp); 127 return true; 128 } 129 130 /* 131 if (dest == NULL || strcmp(dest, "none") == 0) { 132 if (logDest != NULL && logDest != stderr && logDest != stdout) { 133 fclose(logDest); 134 } 135 logDest = NULL; 136 return true; 137 } 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 } 173 if (logDest != NULL && logDest != stderr && logDest != stdout) { 174 fclose(logDest); 175 } 176 logDest = file; 177 return true; 178 } 179 */ 126 // return true; 127 } 128 180 129 return true; 181 130 … … 253 202 } 254 203 204 int psMessageDestination (const char *dest) 205 { 206 char protocol[5]; 207 char location[257]; 208 if (logDest == (FILE *) 1) { 209 logDest = stderr; 210 } 211 212 if (dest == NULL || strcmp(dest, "none") == 0) { 213 if (logDest != NULL && logDest != stderr && logDest != stdout) { 214 fclose(logDest); 215 } 216 logDest = NULL; 217 return 0; 218 } 219 if (sscanf(dest, "%4s:%256s", protocol, location) < 2) { 220 psError(PS_ERR_LOCATION_INVALID, true, 221 PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED, 222 dest); 223 return -1; 224 } 225 if (strcmp(protocol, "dest") == 0) { 226 if (strcmp(location, "stderr") == 0) { 227 if (logDest != NULL && logDest != stderr && logDest != stdout) { 228 fclose(logDest); 229 } 230 logDest = stderr; 231 return 2; 232 } 233 if (strcmp(location, "stdout") == 0) { 234 if (logDest != NULL && logDest != stderr && logDest != stdout) { 235 fclose(logDest); 236 } 237 logDest = stdout; 238 return 1; 239 } 240 psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID, 241 location); 242 return -1; 243 } else if (strcmp(protocol, "file") == 0) { 244 // FILE *file = fopen(location, "w"); 245 int fileD = creat(location, 0666); 246 247 if (fileD == 0) { 248 psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED, 249 location); 250 return -1; 251 } 252 if (logDest != NULL && logDest != stderr && logDest != stdout) { 253 fclose(logDest); 254 } 255 logDest = fdopen(fileD, "w"); 256 return fileD; 257 } 258 return -1; 259 } 260 255 261 #ifndef HOST_NAME_MAX // should be in limits.h 256 262 #define HOST_NAME_MAX 256 -
trunk/psLib/src/sys/psLogMsg.h
r4952 r4979 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2005-09-0 7 00:36:12 $13 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-09-09 01:11:22 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 61 61 ); 62 62 63 /** This procedures uses a string to set the destination for which to send 64 * the corresponding log messages. 65 * 66 * 67 * @return int: The file descriptor location of the message. 68 */ 69 int psMessageDestination( 70 const char *dest ///< Specifies where to send the message 71 ); 72 63 73 /** This procedure logs a message to the destination set by a prior 64 74 * call to psLogSetDestination(), if myLevel is less than the level -
trunk/psLib/src/types/psMetadataConfig.c
r4870 r4979 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 8-24 22:00:53 $12 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-09-09 01:11:23 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 16 16 */ 17 17 18 #include <libxml/parser.h>19 18 #include <fitsio.h> 20 19 #include <string.h> -
trunk/psLib/test/sys/tst_psLogMsg.c
r4951 r4979 16 16 static psS32 testLogMsg04(); 17 17 static psS32 testLogMsg05(); 18 static psS32 testLogMsg06(); 18 19 19 20 testDescription tests[] = { … … 35 36 { 36 37 testLogMsg05, 5, "psLogSetDestination()", 0, false 38 }, 39 { 40 testLogMsg06, 6, "psMessageDestination()", 0, false 37 41 }, 38 42 { … … 236 240 return 0; 237 241 } 242 243 psS32 testLogMsg06() 244 { 245 psS32 i = 0; 246 // FILE* file; 247 int fd; 248 // char line[256]; 249 250 printf("--------------- psMessageDestination(PS_LOG_NONE) ----------------\n"); 251 psMessageDestination("none"); 252 // psLogSetDestination(0); 253 for (i=0;i<10;i++) { 254 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 255 } 256 257 printf("------------- psMessageDestination(PS_LOG_TO_STDERR) -------------\n"); 258 psMessageDestination("dest:stderr"); 259 // psLogSetDestination(2); 260 for (i=0;i<10;i++) { 261 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 262 } 263 264 printf("------------- psMessageDestination(PS_LOG_TO_STDOUT) -------------\n"); 265 psMessageDestination("dest:stdout"); 266 // psLogSetDestination(1); 267 for (i=0;i<10;i++) { 268 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 269 } 270 271 printf("--------------- psMessageDestination(""file:log2.txt"") ---------------\n"); 272 fd = creat("log2.txt", 0666); 273 psMessageDestination("file:log2.txt"); 274 // psLogSetDestination(fd); 275 for (i=0;i<10;i++) { 276 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 277 } 278 279 280 psMessageDestination("none"); 281 FILE *file; 282 char line[257]; 283 // psMessageDestination(-1); 284 // psLogSetDestination(0); 285 printf("--------------------- The Contents of log2.txt -------------------\n"); 286 file = fopen("log2.txt","r"); 287 while ( fgets(line,256,file) != NULL ) { 288 printf("%s",line); 289 } 290 fclose(file); 291 close(fd); 292 293 int fd2 = creat("/eva/log2.txt", 0666); 294 printf("--------------- psMessageDestination(""file:/eva/log.txt"") ----------\n"); 295 psMessageDestination("file:/eva/log2.txt"); 296 // psLogSetDestination(fd2); 297 for ( i=0;i<10;i++) { 298 psLogMsg(__func__, i, "Hello World! My level is %d\n", i); 299 } 300 close(fd2); 301 302 return 0; 303 } -
trunk/psLib/test/sys/verified/tst_psLogMsg.stderr
r4547 r4979 167 167 ---> TESTPOINT PASSED (psLogMsg{psLogSetDestination()} | tst_psLogMsg.c) 168 168 169 /***************************** TESTPOINT ******************************************\ 170 * TestFile: tst_psLogMsg.c * 171 * TestPoint: psLogMsg{psMessageDestination()} * 172 * TestType: Positive * 173 \**********************************************************************************/ 174 175 <DATE><TIME>|<HOST>|A|testLogMsg06 176 Hello World! My level is 0 177 <DATE><TIME>|<HOST>|E|testLogMsg06 178 Hello World! My level is 1 179 <DATE><TIME>|<HOST>|W|testLogMsg06 180 Hello World! My level is 2 181 <DATE><TIME>|<HOST>|I|testLogMsg06 182 Hello World! My level is 3 183 184 ---> TESTPOINT PASSED (psLogMsg{psMessageDestination()} | tst_psLogMsg.c) 185 -
trunk/psLib/test/sys/verified/tst_psLogMsg.stdout
r4547 r4979 21 21 Hello World! My level is 3 22 22 --------------- psLogSetDestination(file:/eva/log.txt) ---------- 23 --------------- psMessageDestination(PS_LOG_NONE) ---------------- 24 ------------- psMessageDestination(PS_LOG_TO_STDERR) ------------- 25 ------------- psMessageDestination(PS_LOG_TO_STDOUT) ------------- 26 <DATE><TIME>|<HOST>|A|testLogMsg06 27 Hello World! My level is 0 28 <DATE><TIME>|<HOST>|E|testLogMsg06 29 Hello World! My level is 1 30 <DATE><TIME>|<HOST>|W|testLogMsg06 31 Hello World! My level is 2 32 <DATE><TIME>|<HOST>|I|testLogMsg06 33 Hello World! My level is 3 34 --------------- psMessageDestination(file:log2.txt) --------------- 35 --------------------- The Contents of log2.txt ------------------- 36 <DATE><TIME>|<HOST>|A|testLogMsg06 37 Hello World! My level is 0 38 <DATE><TIME>|<HOST>|E|testLogMsg06 39 Hello World! My level is 1 40 <DATE><TIME>|<HOST>|W|testLogMsg06 41 Hello World! My level is 2 42 <DATE><TIME>|<HOST>|I|testLogMsg06 43 Hello World! My level is 3 44 --------------- psMessageDestination(file:/eva/log.txt) ----------
Note:
See TracChangeset
for help on using the changeset viewer.
