IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4951


Ignore:
Timestamp:
Sep 6, 2005, 2:15:51 PM (21 years ago)
Author:
drobbin
Message:

Updated/changed psTrace & psLog fxns to use fd (were FILE*) as described in SDRS

Location:
trunk/psLib
Files:
7 edited

Legend:

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

    r4540 r4951  
    1212 *  @author GLG, MHPCC
    1313 *
    14  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-07-12 19:12:01 $
     14 *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-09-07 00:15:48 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3737#include <time.h>
    3838#include <unistd.h>
     39#include <fcntl.h>
    3940
    4041#include "psLogMsg.h"
     
    8788 An psBool: TRUE if successful.
    8889 *****************************************************************************/
    89 bool psLogSetDestination(const char *dest)
     90bool psLogSetDestination(int fd)
    9091{
    91     char protocol[5];
    92     char location[257];
    93 
     92    //    char protocol[5];
     93    //    char location[257];
     94    //    char dest[257];
     95    FILE *fp;
    9496    // if logDest has not been initialized, do so before using it
    9597    if (logDest == (FILE *) 1) {
     
    9799    }
    98100
    99     if (dest == NULL || strcmp(dest, "none") == 0) {
     101    if ( fd == 1 ) {
     102        //        fp = stdout;
    100103        if (logDest != NULL && logDest != stderr && logDest != stdout) {
    101104            fclose(logDest);
    102105        }
     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        }
    103118        logDest = NULL;
    104119        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) {
    116132            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    117133                fclose(logDest);
    118134            }
    119             logDest = stderr;
     135            logDest = NULL;
    120136            return true;
    121137        }
    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            }
    123173            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    124174                fclose(logDest);
    125175            }
    126             logDest = stdout;
     176            logDest = file;
    127177            return true;
    128178        }
    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
    150182}
    151183
  • trunk/psLib/src/sys/psLogMsg.h

    r4556 r4951  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-07-15 02:33:54 $
     13 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-09-07 00:15:48 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333 */
    3434bool psLogSetDestination(
    35     const char *dest                   ///< Specifies where to send messages.
     35    int fd                             ///< Specifies where to send messages.
    3636);
    3737
  • trunk/psLib/src/sys/psTrace.c

    r4944 r4951  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-09-02 21:32:06 $
     11 *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-09-07 00:15:48 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    245245 zero
    246246*****************************************************************************/
    247 psBool psTraceSetLevel(const char *comp,   // component of interest
    248                        int level)  // desired trace level
     247int psTraceSetLevel(const char *comp,   // component of interest
     248                    int level)  // desired trace level
    249249{
    250250    char *compName = NULL;
     251    int prevLevel = -1;
    251252
    252253    // If the root component tree does not exist, then initialize it.
     
    267268        compName = (char *) comp;
    268269    }
    269 
     270    prevLevel = psTraceGetLevel(compName);
    270271    // Add the new component to the component tree.
    271272    if ( !componentAdd(compName, level) ) {
     
    278279            psFree(compName);
    279280        }
    280         return false;
     281        //        return false;
     282        return -1;
    281283    }
    282284
     
    285287    }
    286288
    287     return true;
     289    //    return true;
     290    return prevLevel;
    288291}
    289292
     
    489492void p_psTrace(const char *comp,        // component being traced
    490493               int level,               // desired trace level
     494               const char *format,
    491495               ...)                     // arguments
    492496{
     
    508512    // of it's associatedcomponent.
    509513    if (level <= psTraceGetLevel(comp)) {
    510         va_start(ap, level);
     514        va_start(ap, format);
    511515
    512516        // The following functions get the variable list of parameters with
     
    517521        // We indent each message one space for each level of the message.
    518522        for (i = 0; i < level; i++) {
    519             fprintf(traceFP, " ");
     523            //            fprintf(traceFP, " ");
     524            fprintf(traceFP, "%s", format);
    520525        }
    521526        vfprintf(traceFP, fmt, ap);
     527        //        vfprintf(traceFP, format, ap);
    522528        va_end(ap);
    523529    }
     
    532538    /*
    533539        bool special;
    534      
     540
    535541        // XXX EAM perhaps return an error?
    536542        if (fp == NULL) {
    537543            return;
    538544        }
    539      
     545
    540546        // cannot close traceFP if one of the special FILE ptrs
    541547        special  = (traceFP == NULL);
     
    543549        special |= (traceFP == stdout);
    544550        special |= (traceFP == stderr);
    545      
     551
    546552        if (!special) {
    547553            fclose (traceFP);
  • trunk/psLib/src/sys/psTrace.h

    r4944 r4951  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-09-02 21:32:06 $
     11 *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-09-07 00:15:48 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6464    const char *facil,                 ///< facilty of interest
    6565    int level,                         ///< desired trace level
     66    const char *format,                ///< printf-style format command
    6667    ...                                ///< trace message arguments
    6768);
     
    7273    const char *facil,                 ///< facilty of interest
    7374    psS32 myLevel,                     ///< desired trace level
     75    const char *format,                ///< printf-style format command
    7476    ...                                ///< trace message arguments
    7577);
     
    8385/** Set trace level
    8486 *
    85  *  @return psBool:       True if successful, otherwise false
     87 *  @return int:       The previous level.
    8688 */
    87 psBool psTraceSetLevel(
     89int psTraceSetLevel(
    8890    const char *facil,                 ///< facilty of interest
    8991    int level                          ///< desired trace level
  • trunk/psLib/test/math/tst_psRandom.c

    r4859 r4951  
    1919#include <stdio.h>
    2020#include <math.h>
     21#include <fcntl.h>
     22#include <unistd.h>
    2123#include "pslib_strict.h"
    2224#include "psTest.h"
     
    8082
    8183    // 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);
    8387    myRNG = psRandomAlloc(PS_RANDOM_TAUS, 0);
    84     psLogSetDestination("dest:stderr");
     88    //    psLogSetDestination("dest:stderr");
     89    psLogSetDestination(2);
    8590    if (myRNG == NULL) {
    8691        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
     
    107112        return 6;
    108113    }
     114    close(fd1);
    109115    psFree(myRNG);
    110116
     
    291297    psRandom *myRNG1 = NULL;
    292298    myRNG1 = psRandomAlloc(PS_RANDOM_TAUS, SEED);
    293     psLogSetDestination("file:seed_msglog2.txt");
     299    //    psLogSetDestination("dest:stderr");
     300    psLogSetDestination(0);
    294301    psRandomReset(myRNG1,0);
    295     psLogSetDestination("dest:stderr");
     302    //    psLogSetDestination("dest:stderr");
     303    psLogSetDestination(2);
    296304    psFree(myRNG1);
    297305
  • trunk/psLib/test/sys/tst_psLogMsg.c

    r4547 r4951  
    77#include "pslib_strict.h"
    88#include "psTest.h"
     9#include <unistd.h>
     10#include <fcntl.h>
    911
    1012static psS32 testLogMsg00();
     
    176178{
    177179    psS32 i = 0;
    178     FILE* file;
    179     char line[256];
     180    //    FILE* file;
     181    int fd;
     182    //    char line[256];
    180183
    181184    printf("--------------- psLogSetDestination(PS_LOG_NONE) ----------------\n");
    182     psLogSetDestination("none");
     185    //    psLogSetDestination("none");
     186    psLogSetDestination(0);
    183187    for (i=0;i<10;i++) {
    184188        psLogMsg(__func__, i, "Hello World!  My level is %d\n", i);
     
    186190
    187191    printf("------------- psLogSetDestination(PS_LOG_TO_STDERR) -------------\n");
    188     psLogSetDestination("dest:stderr");
     192    //    psLogSetDestination("dest:stderr");
     193    psLogSetDestination(2);
    189194    for (i=0;i<10;i++) {
    190195        psLogMsg(__func__, i, "Hello World!  My level is %d\n", i);
     
    192197
    193198    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
    198205    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);
    205219    printf("--------------------- The Contents of log.txt -------------------\n");
    206220    file = fopen("log.txt","r");
     
    209223    }
    210224    fclose(file);
    211 
     225    close(fd);
     226
     227    int fd2 = creat("/eva/log.txt", 0666);
    212228    printf("--------------- psLogSetDestination(""file:/eva/log.txt"") ----------\n");
    213     psLogSetDestination("file:/eva/log.txt");
     229    //    psLogSetDestination("file:/eva/log.txt");
     230    psLogSetDestination(fd2);
    214231    for ( i=0;i<10;i++) {
    215232        psLogMsg(__func__, i, "Hello World! My level is %d\n", i);
    216233    }
    217 
    218     return 0;
    219 }
     234    close(fd2);
     235
     236    return 0;
     237}
  • trunk/psLib/test/sys/tst_psTrace.c

    r4944 r4951  
    103103    (void)psTraceSetLevel(".A.B.C.D.E", 5);
    104104
    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");
    108108
    109109    psTracePrintLevels();
     
    208208
    209209        (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",
    211211                0xbeefface);
    212212        (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",
    214214                0xbeefface);
    215215
    216216        (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",
    218218                0xbeefface);
    219219        (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",
    221221                0xbeefface);
    222222
    223223
    224224        (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",
    226226                0xbeefface);
    227227        (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",
    229229                0xbeefface);
    230230
Note: See TracChangeset for help on using the changeset viewer.