IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4979


Ignore:
Timestamp:
Sep 8, 2005, 3:11:23 PM (21 years ago)
Author:
drobbin
Message:

Took xml/parser.h out of MDConfig, added psMessageDestination

Location:
trunk/psLib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psLogMsg.c

    r4952 r4979  
    1212 *  @author GLG, MHPCC
    1313 *
    14  *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-09-07 00:36:12 $
     14 *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-09-09 01:11:22 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9090bool psLogSetDestination(int fd)
    9191{
    92     //    char protocol[5];
    93     //    char location[257];
    94     //    char dest[257];
    9592    FILE *fp;
    9693    // if logDest has not been initialized, do so before using it
     
    9895        logDest = stderr;
    9996    }
     97    if (fd == -1)
     98        return false;
    10099
    101100    if ( fd == 1 ) {
     
    117116        }
    118117        logDest = NULL;
    119         return true;
     118        //        return true;
    120119    } else if (fd > 2) {
    121120        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     
    125124        logDest = fp;
    126125        //        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
    180129    return true;
    181130
     
    253202}
    254203
     204int 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
    255261#ifndef HOST_NAME_MAX                // should be in limits.h
    256262#define HOST_NAME_MAX 256
  • trunk/psLib/src/sys/psLogMsg.h

    r4952 r4979  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-09-07 00:36:12 $
     13 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-09-09 01:11:22 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6161);
    6262
     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 */
     69int psMessageDestination(
     70    const char *dest                   ///< Specifies where to send the message
     71);
     72
    6373/** This procedure logs a message to the destination set by a prior
    6474 *  call to psLogSetDestination(), if myLevel is less than the level
  • trunk/psLib/src/types/psMetadataConfig.c

    r4870 r4979  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-08-24 22:00:53 $
     12*  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-09-09 01:11:23 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1616*/
    1717
    18 #include <libxml/parser.h>
    1918#include <fitsio.h>
    2019#include <string.h>
  • trunk/psLib/test/sys/tst_psLogMsg.c

    r4951 r4979  
    1616static psS32 testLogMsg04();
    1717static psS32 testLogMsg05();
     18static psS32 testLogMsg06();
    1819
    1920testDescription tests[] = {
     
    3536                              {
    3637                                  testLogMsg05, 5, "psLogSetDestination()", 0, false
     38                              },
     39                              {
     40                                  testLogMsg06, 6, "psMessageDestination()", 0, false
    3741                              },
    3842                              {
     
    236240    return 0;
    237241}
     242
     243psS32 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  
    167167---> TESTPOINT PASSED (psLogMsg{psLogSetDestination()} | tst_psLogMsg.c)
    168168
     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  
    2121    Hello World!  My level is 3
    2222--------------- 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.