IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

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

    r1406 r1407  
     1
    12/** @file  psLogMsg.c
    23 *  @brief Procedures for logging messages.
     
    1112 *  @author George Gusciora, MHPCC
    1213 *
    13  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-08-06 22:34:05 $
     14 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-07 00:06:06 $
    1516 *
    1617 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4445
    4546#define MAX_LOG_LINE_LENGTH 128
    46 static FILE* logDest = (FILE*)1;       // flag to initialize to stderr before using.
    47 static int globalLogLevel = PS_LOG_INFO; // log all messages at this or above
    48 static bool logTime = true;            // Flag to include time info
    49 static bool logHost = true;            // Flag to include host info
    50 static bool logLevel = true;           // Flag to include level info
    51 static bool logName = true;            // Flag to include name info
    52 static bool logMsg = true;             // Flag to include message info
     47static FILE *logDest = (FILE *) 1;      // flag to initialize to stderr before using.
     48static int globalLogLevel = PS_LOG_INFO;        // log all messages at this or above
     49static bool logTime = true;     // Flag to include time info
     50static bool logHost = true;     // Flag to include host info
     51static bool logLevel = true;    // Flag to include level info
     52static bool logName = true;     // Flag to include name info
     53static bool logMsg = true;      // Flag to include message info
    5354
    5455/*****************************************************************************
     
    6768
    6869    if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) {
    69         psLogMsg("logmsg", PS_LOG_WARN,
    70                  "Attempt to set invalid logMsg level: %d", level);
     70        psLogMsg("logmsg", PS_LOG_WARN, "Attempt to set invalid logMsg level: %d", level);
    7171        level = (level < MIN_LOG_LEVEL) ? MIN_LOG_LEVEL : MAX_LOG_LEVEL;
    7272    }
    73 
    7473    // Set new global log level
    7574    globalLogLevel = level;
     
    7877    return oldLevel;
    7978}
    80 
    8179
    8280/*****************************************************************************
     
    9189 An integer specifying the old log destination.
    9290 *****************************************************************************/
    93 int psLogSetDestination(const char* dest)
     91int psLogSetDestination(const char *dest)
    9492{
    9593    char protocol[5];
     
    9795
    9896    // if logDest has not been initialized, do so before using it
    99     if (logDest==(FILE*)1) {
     97    if (logDest == (FILE *) 1) {
    10098        logDest = stderr;
    10199    }
    102100
    103     if (dest == NULL || strcmp(dest,"none")==0) {
     101    if (dest == NULL || strcmp(dest, "none") == 0) {
    104102        if (logDest != NULL && logDest != stderr && logDest != stdout) {
    105103            fclose(logDest);
     
    109107    }
    110108
    111     if (sscanf(dest,"%4s:%256s",protocol,location) < 2) {
    112         psError(__func__,"The specified destination, %s, is malformed.", dest);
     109    if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
     110        psError(__func__, "The specified destination, %s, is malformed.", dest);
    113111        return 1;
    114112    }
    115113
    116     if (strcmp(protocol,"dest") == 0) {
    117         if (strcmp(location,"stderr") == 0) {
     114    if (strcmp(protocol, "dest") == 0) {
     115        if (strcmp(location, "stderr") == 0) {
    118116            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    119117                fclose(logDest);
     
    122120            return 0;
    123121        }
    124         if (strcmp(location,"stdout") == 0) {
     122        if (strcmp(location, "stdout") == 0) {
    125123            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    126124                fclose(logDest);
     
    129127            return 0;
    130128        }
    131         psError(__func__,"The location, %s, for protocol 'dest' is invalid.",location);
     129        psError(__func__, "The location, %s, for protocol 'dest' is invalid.", location);
    132130        return 1;
    133     } else
    134         if (strcmp(protocol,"file") == 0) {
    135             FILE* file = fopen(location,"w");
    136             if (file == NULL) {
    137                 psError(__func__,"Could not open file '%s' for output.",location);
    138                 return 1;
    139             }
    140             if (logDest != NULL && logDest != stderr && logDest != stdout) {
    141                 fclose(logDest);
    142             }
    143             logDest = file;
    144             return 0;
    145         }
    146 
    147     psError(__func__,"Do not know how to handle the protocol '%s'.",protocol);
     131    } else if (strcmp(protocol, "file") == 0) {
     132        FILE *file = fopen(location, "w");
     133
     134        if (file == NULL) {
     135            psError(__func__, "Could not open file '%s' for output.", location);
     136            return 1;
     137        }
     138        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     139            fclose(logDest);
     140        }
     141        logDest = file;
     142        return 0;
     143    }
     144
     145    psError(__func__, "Do not know how to handle the protocol '%s'.", protocol);
    148146    return 1;
    149147}
     
    181179        fmt = "THLNM";
    182180    }
    183 
    184181    // Step through each character in the format string.  For each letter
    185182    // in that string, set/unset the appropriate logging.
     
    214211
    215212    if (!logMsg) {
    216         psTrace("utils.logMsg", 1,
    217                 "You must at least log error messages (You chose \"%s\")",
    218                 fmt);
    219     }
    220 }
    221 
    222 
    223 
    224 #if !defined(HOST_NAME_MAX)  // should be in limits.h
    225 #  define HOST_NAME_MAX 256
     213        psTrace("utils.logMsg", 1, "You must at least log error messages (You chose \"%s\")", fmt);
     214    }
     215}
     216
     217#if !defined(HOST_NAME_MAX)                // should be in limits.h
     218#    define HOST_NAME_MAX 256
    226219#endif
     220
    227221/*****************************************************************************
    228222    psVLogMsg(): This routine sends the message, which is a printf style
     
    239233 NULL.
    240234 *****************************************************************************/
    241 void psLogMsgV(const char *name,
    242                int level,
    243                const char *fmt,
    244                va_list ap)
    245 {
    246     static int first = 1;               // Flag for calling gethostname()
     235void psLogMsgV(const char *name, int level, const char *fmt, va_list ap)
     236{
     237    static int first = 1;       // Flag for calling gethostname()
    247238    static char hostname[HOST_NAME_MAX + 1];
     239
    248240    // Buffer for hostname.
    249     char clevel=0;                      // letter-name for level
    250     char head[MAX_LOG_LINE_LENGTH+2];  // the added two are for the ending | and \0
    251     char *head_ptr = head;              // where we've got to in head
     241    char clevel = 0;            // letter-name for level
     242    char head[MAX_LOG_LINE_LENGTH + 2]; // the added two are for the ending | and \0
     243    char *head_ptr = head;      // where we've got to in head
    252244    int maxLength = MAX_LOG_LINE_LENGTH;
    253     time_t clock = time(NULL);          // The current time.
     245    time_t clock = time(NULL);  // The current time.
    254246    struct tm *utc = gmtime(&clock);    // The current gm time.
    255247
    256248    // if logDest has not been initialized, do so before using it
    257     if (logDest==(FILE*)1) {
     249    if (logDest == (FILE *) 1) {
    258250        logDest = stderr;
    259251    }
    260 
    261252    // If logging is off, or if the level is too high, return immediately.
    262253    if ((level > globalLogLevel) || (logDest == NULL)) {
    263254        return;
    264255    }
    265 
    266256    // If I have not been here yet, determine my hostname and save it.
    267257    if (first) {
     
    297287
    298288    default:
    299         psTrace("utils.logMsg", 2, "Invalid logMsg level: %d (%s)\n",
    300                 level, fmt);
     289        psTrace("utils.logMsg", 2, "Invalid logMsg level: %d (%s)\n", level, fmt);
    301290        level = (level < 0) ? 0 : 9;
    302291        break;
     
    307296        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
    308297                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
    309                               utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
     298                              utc->tm_hour, utc->tm_min, utc->tm_sec) - 1;
    310299        head_ptr += strlen(head_ptr);
    311300    }
     
    336325    if (head_ptr > head) {
    337326        *head_ptr++ = '|';
    338     } else
    339         if (!logMsg) { // no output desired
    340             return;
    341         }
     327    } else if (!logMsg) {                  // no output desired
     328        return;
     329    }
    342330    *head_ptr = '\0';
    343331
     
    352340    }
    353341}
    354 
    355342
    356343/*****************************************************************************
     
    369356 NULL
    370357 *****************************************************************************/
    371 void psLogMsg(const char *name,
    372               int level,
    373               const char *fmt,
    374               ...)
     358void psLogMsg(const char *name, int level, const char *fmt, ...)
    375359{
    376360    va_list ap;
Note: See TracChangeset for help on using the changeset viewer.