IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1141


Ignore:
Timestamp:
Jun 29, 2004, 3:58:20 PM (22 years ago)
Author:
desonia
Message:

bug g618 - psLogSetFormat shall support NULL as input.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r1138 r1141  
    1111 *  @author George Gusciora, MHPCC
    1212 *
    13  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-30 01:17:20 $
     13 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-30 01:58:20 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434#include <time.h>
    3535#include <unistd.h>
     36#include <stdbool.h>
     37
    3638#include "psLogMsg.h"
    3739#include "psError.h"
     
    4143#define MIN_LOG_LEVEL 0
    4244#define MAX_LOG_LEVEL 9
     45
     46#define MAX_LOG_LINE_LENGTH 128
    4347static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages
    4448static int p_psGlobalLogLevel = PS_LOG_INFO;     // log all messages at this or above
     
    4751// which information is displayed in
    4852// log messages.
    49 static int p_psLogTime = 1;                // Flag to include time info
    50 static int p_psLogHost = 1;                // Flag to include host info
    51 static int p_psLogLevel = 1;               // Flag to include level info
    52 static int p_psLogName = 1;                // Flag to include name info
    53 static int p_psLogMsg = 1;                 // Flag to include message info
     53static bool p_psLogTime = true;        // Flag to include time info
     54static bool p_psLogHost = true;        // Flag to include host info
     55static bool p_psLogLevel = true;       // Flag to include level info
     56static bool p_psLogName = true;        // Flag to include name info
     57static bool p_psLogMsg = true;         // Flag to include message info
    5458/*****************************************************************************
    5559psLogSetLevel(): Set the current log level and return old level.
     
    133137void psLogSetFormat(const char *fmt)
    134138{
     139    // assume nothing desired unless specified
     140    p_psLogHost = false;
     141    p_psLogLevel = false;
     142    p_psLogMsg = false;
     143    p_psLogName = false;
     144    p_psLogTime = false;
     145
     146    // if fmt is NULL, no logging is desired.
     147    if (fmt == NULL) {
     148        return;
     149    }
    135150
    136151    // Step through each character in the format string.  For each letter
     
    141156        case 'H':
    142157        case 'h':
    143             p_psLogHost = 1;
     158            p_psLogHost = true;
    144159            break;
    145160        case 'L':
    146161        case 'l':
    147             p_psLogLevel = 1;
     162            p_psLogLevel = true;
    148163            break;
    149164        case 'M':
    150165        case 'm':
    151             p_psLogMsg = 1;
     166            p_psLogMsg = true;
    152167            break;
    153168        case 'N':
    154169        case 'n':
    155             p_psLogName = 1;
     170            p_psLogName = true;
    156171            break;
    157172        case 'T':
    158173        case 't':
    159             p_psLogTime = 1;
     174            p_psLogTime = true;
    160175            break;
    161176        default:
     
    200215    // Buffer for hostname.
    201216    char clevel=0;                      // letter-name for level
    202     char head[HOST_NAME_MAX + 40];      // yes, this is long enough
     217    char head[MAX_LOG_LINE_LENGTH+2];   // the added two are for the ending | and \0
    203218    char *head_ptr = head;              // where we've got to in head
     219    int maxLength = MAX_LOG_LINE_LENGTH;
    204220    time_t clock = time(NULL);          // The current time.
    205221    struct tm *utc = gmtime(&clock);    // The current gm time.
     
    251267    // Create the various log fields...
    252268    if (p_psLogTime) {
    253         sprintf(head_ptr, "%4d:%02d:%02d %02d:%02d:%02dZ",
    254                 utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
    255                 utc->tm_hour, utc->tm_min, utc->tm_sec);
     269        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
     270                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
     271                              utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
    256272        head_ptr += strlen(head_ptr);
    257273    }
     
    261277            *head_ptr++ = '|';
    262278        }
    263         sprintf(head_ptr, "%-20s", hostname);
     279        maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname);
    264280        head_ptr += strlen(head_ptr);
    265281    }
     
    268284            *head_ptr++ = '|';
    269285        }
    270         sprintf(head_ptr, "%c", clevel);
     286        maxLength -= snprintf(head_ptr, maxLength, "%c", clevel);
    271287        head_ptr += strlen(head_ptr);
    272288    }
     
    276292            *head_ptr++ = '|';
    277293        }
    278         sprintf(head_ptr, "%15.15s", name);
     294        maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name);
    279295        head_ptr += strlen(head_ptr);
    280296    }
  • trunk/psLib/src/sysUtils/psLogMsg.c

    r1138 r1141  
    1111 *  @author George Gusciora, MHPCC
    1212 *
    13  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-30 01:17:20 $
     13 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-30 01:58:20 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434#include <time.h>
    3535#include <unistd.h>
     36#include <stdbool.h>
     37
    3638#include "psLogMsg.h"
    3739#include "psError.h"
     
    4143#define MIN_LOG_LEVEL 0
    4244#define MAX_LOG_LEVEL 9
     45
     46#define MAX_LOG_LINE_LENGTH 128
    4347static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages
    4448static int p_psGlobalLogLevel = PS_LOG_INFO;     // log all messages at this or above
     
    4751// which information is displayed in
    4852// log messages.
    49 static int p_psLogTime = 1;                // Flag to include time info
    50 static int p_psLogHost = 1;                // Flag to include host info
    51 static int p_psLogLevel = 1;               // Flag to include level info
    52 static int p_psLogName = 1;                // Flag to include name info
    53 static int p_psLogMsg = 1;                 // Flag to include message info
     53static bool p_psLogTime = true;        // Flag to include time info
     54static bool p_psLogHost = true;        // Flag to include host info
     55static bool p_psLogLevel = true;       // Flag to include level info
     56static bool p_psLogName = true;        // Flag to include name info
     57static bool p_psLogMsg = true;         // Flag to include message info
    5458/*****************************************************************************
    5559psLogSetLevel(): Set the current log level and return old level.
     
    133137void psLogSetFormat(const char *fmt)
    134138{
     139    // assume nothing desired unless specified
     140    p_psLogHost = false;
     141    p_psLogLevel = false;
     142    p_psLogMsg = false;
     143    p_psLogName = false;
     144    p_psLogTime = false;
     145
     146    // if fmt is NULL, no logging is desired.
     147    if (fmt == NULL) {
     148        return;
     149    }
    135150
    136151    // Step through each character in the format string.  For each letter
     
    141156        case 'H':
    142157        case 'h':
    143             p_psLogHost = 1;
     158            p_psLogHost = true;
    144159            break;
    145160        case 'L':
    146161        case 'l':
    147             p_psLogLevel = 1;
     162            p_psLogLevel = true;
    148163            break;
    149164        case 'M':
    150165        case 'm':
    151             p_psLogMsg = 1;
     166            p_psLogMsg = true;
    152167            break;
    153168        case 'N':
    154169        case 'n':
    155             p_psLogName = 1;
     170            p_psLogName = true;
    156171            break;
    157172        case 'T':
    158173        case 't':
    159             p_psLogTime = 1;
     174            p_psLogTime = true;
    160175            break;
    161176        default:
     
    200215    // Buffer for hostname.
    201216    char clevel=0;                      // letter-name for level
    202     char head[HOST_NAME_MAX + 40];      // yes, this is long enough
     217    char head[MAX_LOG_LINE_LENGTH+2];   // the added two are for the ending | and \0
    203218    char *head_ptr = head;              // where we've got to in head
     219    int maxLength = MAX_LOG_LINE_LENGTH;
    204220    time_t clock = time(NULL);          // The current time.
    205221    struct tm *utc = gmtime(&clock);    // The current gm time.
     
    251267    // Create the various log fields...
    252268    if (p_psLogTime) {
    253         sprintf(head_ptr, "%4d:%02d:%02d %02d:%02d:%02dZ",
    254                 utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
    255                 utc->tm_hour, utc->tm_min, utc->tm_sec);
     269        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
     270                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
     271                              utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
    256272        head_ptr += strlen(head_ptr);
    257273    }
     
    261277            *head_ptr++ = '|';
    262278        }
    263         sprintf(head_ptr, "%-20s", hostname);
     279        maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname);
    264280        head_ptr += strlen(head_ptr);
    265281    }
     
    268284            *head_ptr++ = '|';
    269285        }
    270         sprintf(head_ptr, "%c", clevel);
     286        maxLength -= snprintf(head_ptr, maxLength, "%c", clevel);
    271287        head_ptr += strlen(head_ptr);
    272288    }
     
    276292            *head_ptr++ = '|';
    277293        }
    278         sprintf(head_ptr, "%15.15s", name);
     294        maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name);
    279295        head_ptr += strlen(head_ptr);
    280296    }
Note: See TracChangeset for help on using the changeset viewer.