IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1013


Ignore:
Timestamp:
Jun 11, 2004, 7:50:01 PM (22 years ago)
Author:
gusciora
Message:

cosmetics...

Location:
trunk/psLib/src
Files:
9 edited

Legend:

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

    r979 r1013  
    1 /*****************************************************************************
    2     A simple implementation of a logging facility for Pan-STARRS
    3  
     1/** @file  psLogMsg.c
     2 *  @brief Procedures for logging messages.
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedure which set
     6 *  message log levels, messahe log formats, message log destinations, and
     7 *  for generating the messages themselves.
     8 *  @ingroup LogTrace
     9 *
     10 *  @author Robert Lupton, Princeton University
     11 *  @author George Gusciora, MHPCC
     12 *
     13 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-12 05:50:01 $
     15 *
     16 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     17 */
     18
     19/*****************************************************************************
    420NOTES: currently, the prototype code has the following global variables:
    5     static int logDest;
    6     static int logLevel;
    7     static int log_time;
    8     static int log_host;
    9     static int log_level;
    10     static int log_name;
    11     static int log_msg;
     21    static int p_psGlobalLogDest;
     22    static int p_psGlobalLogLevel;
     23    static int p_psLogTime;
     24    static int p_psLogHost;
     25    static int p_psLogLevel;
     26    static int p_psLogName;
     27    static int p_psLogMsg;
    1228 *****************************************************************************/
    1329#include <limits.h>
     
    1834#include <time.h>
    1935#include <unistd.h>
    20 
    21 /* #include "psLib.h" */
    2236#include "psLogMsg.h"
    2337#include "psError.h"
     
    2741#define MIN_LOG_LEVEL 0
    2842#define MAX_LOG_LEVEL 9
    29 static int logDest = PS_LOG_TO_STDERR; // where to log messages
    30 static int logLevel = PS_LOG_INFO;     // log all messages at this or above
     43static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages
     44static int p_psGlobalLogLevel = PS_LOG_INFO;     // log all messages at this or above
    3145//static FILE *p_logFP = NULL;
    3246// The following variables control
    3347// which information is displayed in
    3448// log messages.
    35 static int log_time = 1;                // Flag to include time info
    36 static int log_host = 1;                // Flag to include host info
    37 static int log_level = 1;               // Flag to include level info
    38 static int log_name = 1;                // Flag to include name info
    39 static int log_msg = 1;                 // Flag to include message info
     49static int p_psLogTime = 1;                // Flag to include time info
     50static int p_psLogHost = 1;                // Flag to include host info
     51static int p_psLogLevel = 1;               // Flag to include level info
     52static int p_psLogName = 1;                // Flag to include name info
     53static int p_psLogMsg = 1;                 // Flag to include message info
    4054/*****************************************************************************
    4155psLogSetLevel(): Set the current log level and return old level.
     
    4963int psLogSetLevel(int level)
    5064{
    51     int oldLevel = logLevel;
     65    // Save old global log level for changing it.
     66    int oldLevel = p_psGlobalLogLevel;
    5267
    5368    if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) {
     
    5772    }
    5873
    59     logLevel = level;
     74    // Set new global log level
     75    p_psGlobalLogLevel = level;
     76
     77    // Return old global log level
    6078    return oldLevel;
    6179}
     
    7593int psLogSetDestination(int dest)
    7694{
    77     int old = logDest;
     95    // Save old global log destination before changing it.
     96    int old = p_psGlobalLogDest;
    7897
    7998    switch (dest) {
     
    81100    case PS_LOG_TO_STDOUT:
    82101    case PS_LOG_TO_STDERR:
    83         logDest = dest;
     102        // Set new global log destination
     103        p_psGlobalLogDest = dest;
    84104        break;
    85105
    86106    default:
    87107        // GUS: Should you log this error properly?
    88         fprintf(stderr,"Unknown logDestination: %d (ignored)\n", dest);
    89         break;
    90     }
    91 
     108        fprintf(stderr,"Unknown p_psGlobalLogDest: %d (ignored)\n", dest);
     109        break;
     110    }
     111
     112    // Return old global log destination
    92113    return old;
    93114}
     
    112133void psLogSetFormat(const char *fmt)
    113134{
    114     int nlog_time = 0;
    115     int nlog_host = 0;
    116     int nlog_level = 0;
    117     int nlog_name = 0;
    118     int nlog_msg = 0;
     135
     136    // Step through each character in the format string.  For each letter
     137    // in that string, set/unset the appropriate logging.
    119138
    120139    for (const char *ptr = fmt; *ptr != '\0'; ptr++) {
     
    122141        case 'H':
    123142        case 'h':
    124             nlog_host = 1;
     143            p_psLogHost = 1;
    125144            break;
    126145        case 'L':
    127146        case 'l':
    128             nlog_level = 1;
     147            p_psLogLevel = 1;
    129148            break;
    130149        case 'M':
    131150        case 'm':
    132             nlog_msg = 1;
     151            p_psLogMsg = 1;
    133152            break;
    134153        case 'N':
    135154        case 'n':
    136             nlog_name = 1;
     155            p_psLogName = 1;
    137156            break;
    138157        case 'T':
    139158        case 't':
    140             nlog_time = 1;
     159            p_psLogTime = 1;
    141160            break;
    142161        default:
    143             // GUS: figure out the psError() format:
    144             //     psError(__func__, PS_ERR_UNKNOWN, 1,
    145             //            "Unknown logging keyword %c", *ptr);
    146162            psError(__func__, "Unknown logging keyword %c", *ptr);
    147163            break;
     
    149165    }
    150166
    151     if (!nlog_msg) {
     167    if (!p_psLogMsg) {
    152168        psTrace("utils.logMsg", 1,
    153169                "You must at least log error messages (You chose \"%s\")",
    154170                fmt);
    155171    }
    156 
    157     log_host = nlog_host;
    158     log_level = nlog_level;
    159     log_msg = nlog_msg;
    160     log_name = nlog_name;
    161     log_time = nlog_time;
    162172}
    163173
     
    186196               va_list ap)
    187197{
    188     static int first = 1;
     198    static int first = 1;               // Flag for calling gethostname()
    189199    static char hostname[HOST_NAME_MAX + 1];
     200    // Buffer for hostname.
    190201    char clevel=0;                      // letter-name for level
    191202    char head[HOST_NAME_MAX + 40];      // yes, this is long enough
    192203    char *head_ptr = head;              // where we've got to in head
    193     time_t clock = time(NULL);
    194     struct tm *utc = gmtime(&clock);
    195 
    196     if ((level > logLevel) || (logDest == PS_LOG_NONE)) {
     204    time_t clock = time(NULL);          // The current time.
     205    struct tm *utc = gmtime(&clock);    // The current gm time.
     206
     207    // If logging is off, or if the level is too high, return immediately.
     208    if ((level > p_psGlobalLogLevel) || (p_psGlobalLogDest == PS_LOG_NONE)) {
    197209        return;
    198210    }
    199211
     212    // If I have not been here yet, determine my hostname and save it.
    200213    if (first) {
    201214        first = 0;
     
    236249    }
    237250
    238 
    239     if (log_time) {
     251    // Create the various log fields...
     252    if (p_psLogTime) {
    240253        sprintf(head_ptr, "%4d:%02d:%02d %02d:%02d:%02dZ",
    241254                utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
     
    243256        head_ptr += strlen(head_ptr);
    244257    }
    245     if (log_host) {
     258    // Hostname should be 20 characters.
     259    if (p_psLogHost) {
    246260        if (head_ptr > head) {
    247261            *head_ptr++ = '|';
     
    250264        head_ptr += strlen(head_ptr);
    251265    }
    252     if (log_level) {
     266    if (p_psLogLevel) {
    253267        if (head_ptr > head) {
    254268            *head_ptr++ = '|';
     
    257271        head_ptr += strlen(head_ptr);
    258272    }
    259     if (log_name) {
     273    // The name field must be 15 characters.
     274    if (p_psLogName) {
    260275        if (head_ptr > head) {
    261276            *head_ptr++ = '|';
    262277        }
    263         sprintf(head_ptr, "%-15s", name);
     278        sprintf(head_ptr, "%15.15s", name);
    264279        head_ptr += strlen(head_ptr);
    265280    }
     
    270285    *head_ptr = '\0';
    271286
    272     switch (logDest) {
     287    switch (p_psGlobalLogDest) {
    273288    case PS_LOG_TO_STDOUT:
    274289        puts(head);
    275         if (log_msg) {
     290        if (p_psLogMsg) {
    276291            vprintf(fmt, ap);
    277292            if (fmt[strlen(fmt) - 1] != '\n') {
     
    285300    case PS_LOG_TO_STDERR:
    286301        fputs(head, stderr);
    287         if (log_msg) {
     302        if (p_psLogMsg) {
    288303            vfprintf(stderr, fmt, ap);
    289304            if (fmt[strlen(fmt) - 1] != '\n') {
  • trunk/psLib/src/sys/psLogMsg.h

    r979 r1013  
     1/** @file  psLogMsg.h
     2 *  @brief Procedures for logging messages.
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedure which set
     6 *  message log levels, messahe log formats, message log destinations, and
     7 *  for generating the messages themselves.
     8 *  @ingroup LogTrace
     9 *
     10 *  @author Robert Lupton, Princeton University
     11 *  @author George Gusciora, MHPCC
     12 *
     13 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-12 05:50:01 $
     15 *
     16 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     17 */
    118#if !defined(PS_LOG_MSG_H)
    219#define PS_LOG_MSG_H
    3 
    4 /** \file psLogMsg.h
    5  *  \brief log messaging facilities
    6  *  \ingroup LogTrace
    7  */
    8 
    920#include <stdarg.h>
    1021
     
    1829/// In future versions, this procedure will take a character string as an
    1930/// argument which can specify more general log destinations.
    20 int psLogSetDestination(int dest);
     31int psLogSetDestination(int dest     ///< Specifies where to send messages.
     32                       );
     33
    2134
    2235/// This procedure sets the message level for future log messages.  Subsequent
     
    2538/// Ie. higher values set by this procedure will cause more log messages to
    2639/// be displayed.
    27 int psLogSetLevel(int level);
     40int psLogSetLevel(int level          ///< Specifies the system log level
     41                 );
     42
    2843
    2944/// This procedure sets the log format for future log messages.  The argument
     
    3247/// Deleting a letter from the string will cause the associated information
    3348/// to not be logged.
    34 void psLogSetFormat(const char *fmt);
     49void psLogSetFormat(const char *fmt ///< Specifies the system log format
     50                   );
    3551
    3652
     
    4157void psLogMsg(const char *name,     ///< name of the log source
    4258              int myLevel,          ///< severity level of this log message
    43               const char *fmt, ...) ///< printf-style format command
    44 ;
    45 
     59              const char *fmt, ...  ///< printf-style format command
     60             );
    4661
    4762
     
    5166               int myLevel,      ///< severity level of this log message
    5267               const char *fmt,  ///< printf-style format command
    53                va_list ap)       ///< varargs argument list
    54 ;
    55 
     68               va_list ap        ///< varargs argument list
     69              );
    5670
    5771///< Status codes for log messages
  • trunk/psLib/src/sys/psTrace.c

    r928 r1013  
    1 /*****************************************************************************
    2     A simple implementation of a tracing facility for Pan-STARRS.  Tracing
    3     is controlled on a per "component" basis, where a "component" is a name
    4     of the form aaa.bbb.ccc where aaa is the most significant part.
    5  
     1/** @file psTrace.c
     2 *  \brief basic run-time trace facilities
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the code for procedures to insert
     6 *  trace messages into the code.
     7 *
     8 *  @author Robert Lupton, Princeton University
     9 *  @author George Gusciora, MHPCC
     10 *
     11 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-12 05:50:01 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
     16/*****************************************************************************
    617    NOTES:
    718 In the SRD, higher trace levels correspond to a numerically lower trace
     
    1627 trace level of that node.
    1728 
    18  This code is obfuscated by the fact that component names are of the form
    19  ".a.b.c.d" where "." is always the root of the tree, and for tree that have
    20  a depth of 3 or higher (including the root ".") the "."  character is also
    21  the deliminator between different individual nodes in the full component
    22  name.  So, for ".a.b.c.d", the first "." signifies the root of the tree,
    23  while the last three dots merely act as separators between the node names
    24  "b", "c", and "d".
    25  
    2629 I added a function psTraceFree() which frees all nodes in the trace component
    2730 tree.  Previously, there had been no function in the API which accomplished
     
    3235#include <string.h>
    3336#include <stdarg.h>
    34 /* #include "pslib.h" */
    3537#include "psMemory.h"
    3638#include "psTrace.h"
     
    3840#include "psError.h"
    3941
    40 static Component *croot = NULL;           // The root of the trace component
    41 static FILE *traceFP = NULL;
    42 /*****************************************************************************
    43     componentAlloc(): allocate memory for a new node, and initialize members.
     42static Component *p_psCroot = NULL;       // The root of the trace component
     43static FILE *p_psTraceFP = NULL;          // File destination for messages.
     44/*****************************************************************************
     45componentAlloc(): allocate memory for a new node, and initialize members.
    4446 *****************************************************************************/
    4547Component *componentAlloc(const char *name,
     
    5658
    5759/*****************************************************************************
    58     componentFree(): free the current node in the root tree, and all
    59  children nodes as well.
     60componentFree(): free the current node in the root tree, and all children
     61nodes as well.
    6062 *****************************************************************************/
    6163static void componentFree(Component *comp)
     
    7880
    7981/*****************************************************************************
    80     initTrace(): simply initialize the component root tree.
     82initTrace(): simply initialize the component root tree.
    8183*****************************************************************************/
    8284static void initTrace(void)
    8385{
    84     if (croot == NULL) {
    85         croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
    86     }
    87 }
    88 
    89 
    90 /*****************************************************************************
    91     Set all trace levels to zero.
     86    if (p_psCroot == NULL) {
     87        p_psCroot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
     88    }
     89}
     90
     91
     92/*****************************************************************************
     93Set all trace levels to zero.
    9294 *****************************************************************************/
    9395void p_psTraceReset(Component *currentNode)
     
    112114}
    113115
     116/*****************************************************************************
     117Set all trace levels to zero.
     118 *****************************************************************************/
    114119void psTraceReset()
    115120{
    116     p_psTraceReset(croot);
    117 }
    118 
    119 
     121    p_psTraceReset(p_psCroot);
     122}
     123
     124
     125/*****************************************************************************
     126Free all nodes in the component tree.
     127 *****************************************************************************/
    120128void psTraceFree()
    121129{
    122     componentFree(croot);
    123 }
    124 
    125 
    126 /*****************************************************************************
    127     componentAdd(): Adds the component named "addNodeName" to the root tree.
     130    componentFree(p_psCroot);
     131}
     132
     133
     134/*****************************************************************************
     135componentAdd(): Adds the component named "addNodeName" to the root tree.
    128136 
    129     NOTE: replace the call to strsep() with a call to strtok(), which conforms
    130     to ANSI-C.
     137NOTE: replace the call to strsep() with a call to strtok(), which conforms
     138to ANSI-C.
    131139 *****************************************************************************/
    132140static void componentAdd(const char *addNodeName,
    133141                         int         level)
    134142{
    135     int        i = 0;
    136     char       name[strlen(addNodeName) + 1];
    137     // buffer for writeable copy.
     143    int        i = 0;                         // Loop index variable.
     144    char       name[strlen(addNodeName) + 1]; // buffer for writeable copy.
    138145    char      *pname=name;
    139146    char      *firstComponent = NULL;       // first component of name
    140     Component *currentNode = croot;
     147    Component *currentNode = p_psCroot;
    141148    int        nodeExists = 0;
    142149
    143150    // Is this the root node?  If so, simply set level and return.
    144151    if (strcmp(".", addNodeName) == 0) {
    145         croot->level = level;
     152        p_psCroot->level = level;
    146153        return;
    147154    }
     
    199206{
    200207    // If the root component tree does not exist, then initialize it.
    201     if (croot == NULL) {
     208    if (p_psCroot == NULL) {
    202209        initTrace();
    203210    }
     
    230237    char      *pname=name;
    231238    char      *firstComponent = NULL;   // first component of name
    232     Component *currentNode = croot;
     239    Component *currentNode = p_psCroot;
    233240    int        i = 0;
    234241
     
    238245
    239246    if (strcmp(".", aname) == 0) {
    240         return(croot->level);
     247        return(p_psCroot->level);
    241248    }
    242249
     
    282289int psTraceGetLevel(const char *name)
    283290{
    284     if (croot == NULL) {
     291    if (p_psCroot == NULL) {
    285292        return(UNKNOWN_TRACE_LEVEL);
    286293    }
     
    328335
    329336/*****************************************************************************
    330     psPrintTraceLevels()
    331  Simply print all the trace levels in the trace level component tree.
    332     Inputs:
    333  none
    334     Outputs:
    335  none
    336     Returns:
     337psPrintTraceLevels(): Simply print all the trace levels in the trace level
     338component tree.
     339Inputs:
     340 none
     341Outputs:
     342 none
     343Returns:
    337344 null
    338345*****************************************************************************/
    339346void psTracePrintLevels(void)
    340347{
    341     if (croot == NULL) {
     348    if (p_psCroot == NULL) {
    342349        return;
    343350    }
    344351
    345     doPrintTraceLevels(croot, 0);
    346 }
    347 
    348 
    349 /*****************************************************************************
    350     p_psTrace(): we display the trace message to standard output if the trace
    351  level of that message, supplied by the parameter "level" is higher
    352  than the trace level that is currently associated with the component
    353  named by the parameter "comp".
    354     Input:
     352    doPrintTraceLevels(p_psCroot, 0);
     353}
     354
     355
     356/*****************************************************************************
     357p_psTrace(): we display the trace message to standard output if the trace
     358level of that message, supplied by the parameter "level" is higher than the
     359trace level that is currently associated with the component named by the
     360parameter "comp".
     361Input:
    355362 comp
    356363 level
    357364 ...  a printf-style output string.
    358     Output:
    359  none
    360     Return:
     365Output:
     366 none
     367Return:
    361368 null
    362369 *****************************************************************************/
     
    384391        fmt = va_arg(ap, char *);
    385392
    386         if (traceFP != NULL) {
     393        if (p_psTraceFP != NULL) {
    387394            // We indent each message one space for each level of the message.
    388395            for (i = 0; i < level; i++) {
    389                 fprintf(traceFP, " ");
     396                fprintf(p_psTraceFP, " ");
    390397            }
    391             vfprintf(traceFP, fmt, ap);
     398            vfprintf(p_psTraceFP, fmt, ap);
    392399        } else {
    393400            // We indent each message one space for each level of the message.
     
    405412void psTraceSetDestination(FILE *fp)
    406413{
    407     traceFP = fp;
    408 }
     414    p_psTraceFP = fp;
     415}
  • trunk/psLib/src/sys/psTrace.h

    r978 r1013  
     1/** @file psTrace.h
     2 *  \brief basic run-time trace facilities
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedures to insert
     6 *  trace messages into the code.
     7 *
     8 *  @author Robert Lupton, Princeton University
     9 *  @author George Gusciora, MHPCC
     10 *
     11 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-12 05:50:01 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
    116#if !defined(PS_TRACE_H)
    217#define PS_TRACE_H 1
     
    419#define DEFAULT_TRACE_LEVEL 0
    520
    6 /** \file psTrace.h
    7  *  \brief basic run-time trace facilities
    8  *  \ingroup LogTrace
    9  */
    10 
    11 /*****************************************************************************
    12     A component is a string of the form aaa.bbb.ccc, and may itself contain
    13     further subcomponents.  The Component structure doesn't in fact contain
    14     it's full name, but only the last part.
    15  *****************************************************************************/
     21/** Basic structure for the component tree.  A component is a string of the
     22    form aaa.bbb.ccc, and may itself contain further subcomponents.  The
     23    Component structure doesn't in fact contain it's full name, but only the
     24    last part. */
    1625typedef struct Component
    1726{
     
    2635 *  \{
    2736 */
    28 
    2937
    3038/** Functions **************************************************************/
     
    5967;
    6068
     69/// Set the destination of future trace messages.
    6170void psTraceSetDestination(FILE *fp);
    6271
  • trunk/psLib/src/sysUtils/psHash.h

    r1012 r1013  
    11/** @file  psHash.h
    2  *
    32 *  @brief Contains support for basic hashing functions.
     3 *  @ingroup HashTable
    44 *
    55 *  This file will hold the prototypes for defining a hash table with arbitrary
     
    77 *  data from that hash table, and listing all keys defined in the hash table.
    88 *
    9  *  @ingroup HashTable
    10  *
    119 *  @author Robert Lupton, Princeton University
    1210 *  @author George Gusciora, MHPCC
    1311 *   
    14  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-06-12 04:55:21 $
     12 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-12 05:50:01 $
    1614 *
    1715 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1816 */
    19 
    2017#if !defined(PS_HASH_H)
    2118#define PS_HASH_H
     
    2522 */
    2623#include "psList.h"
    27 
    2824
    2925/** A bucket that holds an item of data. */
     
    4036typedef struct psHash
    4137{
    42     int nbucket;                        //< Number of buckets in hash table.
    43     psHashBucket **buckets;             //< The bucket data.
     38    int nbucket;                        ///< Number of buckets in hash table.
     39    psHashBucket **buckets;             ///< The bucket data.
    4440}
    4541psHash;
    4642
    4743/// Allocate hash buckets in table.
    48 psHash *psHashAlloc(int nbucket);
     44psHash *psHashAlloc(int nbucket       ///< The number of buckets to allocate.
     45                   );
    4946
    5047/// Free hash buckets from table.
  • trunk/psLib/src/sysUtils/psLogMsg.c

    r979 r1013  
    1 /*****************************************************************************
    2     A simple implementation of a logging facility for Pan-STARRS
    3  
     1/** @file  psLogMsg.c
     2 *  @brief Procedures for logging messages.
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedure which set
     6 *  message log levels, messahe log formats, message log destinations, and
     7 *  for generating the messages themselves.
     8 *  @ingroup LogTrace
     9 *
     10 *  @author Robert Lupton, Princeton University
     11 *  @author George Gusciora, MHPCC
     12 *
     13 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-12 05:50:01 $
     15 *
     16 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     17 */
     18
     19/*****************************************************************************
    420NOTES: currently, the prototype code has the following global variables:
    5     static int logDest;
    6     static int logLevel;
    7     static int log_time;
    8     static int log_host;
    9     static int log_level;
    10     static int log_name;
    11     static int log_msg;
     21    static int p_psGlobalLogDest;
     22    static int p_psGlobalLogLevel;
     23    static int p_psLogTime;
     24    static int p_psLogHost;
     25    static int p_psLogLevel;
     26    static int p_psLogName;
     27    static int p_psLogMsg;
    1228 *****************************************************************************/
    1329#include <limits.h>
     
    1834#include <time.h>
    1935#include <unistd.h>
    20 
    21 /* #include "psLib.h" */
    2236#include "psLogMsg.h"
    2337#include "psError.h"
     
    2741#define MIN_LOG_LEVEL 0
    2842#define MAX_LOG_LEVEL 9
    29 static int logDest = PS_LOG_TO_STDERR; // where to log messages
    30 static int logLevel = PS_LOG_INFO;     // log all messages at this or above
     43static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages
     44static int p_psGlobalLogLevel = PS_LOG_INFO;     // log all messages at this or above
    3145//static FILE *p_logFP = NULL;
    3246// The following variables control
    3347// which information is displayed in
    3448// log messages.
    35 static int log_time = 1;                // Flag to include time info
    36 static int log_host = 1;                // Flag to include host info
    37 static int log_level = 1;               // Flag to include level info
    38 static int log_name = 1;                // Flag to include name info
    39 static int log_msg = 1;                 // Flag to include message info
     49static int p_psLogTime = 1;                // Flag to include time info
     50static int p_psLogHost = 1;                // Flag to include host info
     51static int p_psLogLevel = 1;               // Flag to include level info
     52static int p_psLogName = 1;                // Flag to include name info
     53static int p_psLogMsg = 1;                 // Flag to include message info
    4054/*****************************************************************************
    4155psLogSetLevel(): Set the current log level and return old level.
     
    4963int psLogSetLevel(int level)
    5064{
    51     int oldLevel = logLevel;
     65    // Save old global log level for changing it.
     66    int oldLevel = p_psGlobalLogLevel;
    5267
    5368    if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) {
     
    5772    }
    5873
    59     logLevel = level;
     74    // Set new global log level
     75    p_psGlobalLogLevel = level;
     76
     77    // Return old global log level
    6078    return oldLevel;
    6179}
     
    7593int psLogSetDestination(int dest)
    7694{
    77     int old = logDest;
     95    // Save old global log destination before changing it.
     96    int old = p_psGlobalLogDest;
    7897
    7998    switch (dest) {
     
    81100    case PS_LOG_TO_STDOUT:
    82101    case PS_LOG_TO_STDERR:
    83         logDest = dest;
     102        // Set new global log destination
     103        p_psGlobalLogDest = dest;
    84104        break;
    85105
    86106    default:
    87107        // GUS: Should you log this error properly?
    88         fprintf(stderr,"Unknown logDestination: %d (ignored)\n", dest);
    89         break;
    90     }
    91 
     108        fprintf(stderr,"Unknown p_psGlobalLogDest: %d (ignored)\n", dest);
     109        break;
     110    }
     111
     112    // Return old global log destination
    92113    return old;
    93114}
     
    112133void psLogSetFormat(const char *fmt)
    113134{
    114     int nlog_time = 0;
    115     int nlog_host = 0;
    116     int nlog_level = 0;
    117     int nlog_name = 0;
    118     int nlog_msg = 0;
     135
     136    // Step through each character in the format string.  For each letter
     137    // in that string, set/unset the appropriate logging.
    119138
    120139    for (const char *ptr = fmt; *ptr != '\0'; ptr++) {
     
    122141        case 'H':
    123142        case 'h':
    124             nlog_host = 1;
     143            p_psLogHost = 1;
    125144            break;
    126145        case 'L':
    127146        case 'l':
    128             nlog_level = 1;
     147            p_psLogLevel = 1;
    129148            break;
    130149        case 'M':
    131150        case 'm':
    132             nlog_msg = 1;
     151            p_psLogMsg = 1;
    133152            break;
    134153        case 'N':
    135154        case 'n':
    136             nlog_name = 1;
     155            p_psLogName = 1;
    137156            break;
    138157        case 'T':
    139158        case 't':
    140             nlog_time = 1;
     159            p_psLogTime = 1;
    141160            break;
    142161        default:
    143             // GUS: figure out the psError() format:
    144             //     psError(__func__, PS_ERR_UNKNOWN, 1,
    145             //            "Unknown logging keyword %c", *ptr);
    146162            psError(__func__, "Unknown logging keyword %c", *ptr);
    147163            break;
     
    149165    }
    150166
    151     if (!nlog_msg) {
     167    if (!p_psLogMsg) {
    152168        psTrace("utils.logMsg", 1,
    153169                "You must at least log error messages (You chose \"%s\")",
    154170                fmt);
    155171    }
    156 
    157     log_host = nlog_host;
    158     log_level = nlog_level;
    159     log_msg = nlog_msg;
    160     log_name = nlog_name;
    161     log_time = nlog_time;
    162172}
    163173
     
    186196               va_list ap)
    187197{
    188     static int first = 1;
     198    static int first = 1;               // Flag for calling gethostname()
    189199    static char hostname[HOST_NAME_MAX + 1];
     200    // Buffer for hostname.
    190201    char clevel=0;                      // letter-name for level
    191202    char head[HOST_NAME_MAX + 40];      // yes, this is long enough
    192203    char *head_ptr = head;              // where we've got to in head
    193     time_t clock = time(NULL);
    194     struct tm *utc = gmtime(&clock);
    195 
    196     if ((level > logLevel) || (logDest == PS_LOG_NONE)) {
     204    time_t clock = time(NULL);          // The current time.
     205    struct tm *utc = gmtime(&clock);    // The current gm time.
     206
     207    // If logging is off, or if the level is too high, return immediately.
     208    if ((level > p_psGlobalLogLevel) || (p_psGlobalLogDest == PS_LOG_NONE)) {
    197209        return;
    198210    }
    199211
     212    // If I have not been here yet, determine my hostname and save it.
    200213    if (first) {
    201214        first = 0;
     
    236249    }
    237250
    238 
    239     if (log_time) {
     251    // Create the various log fields...
     252    if (p_psLogTime) {
    240253        sprintf(head_ptr, "%4d:%02d:%02d %02d:%02d:%02dZ",
    241254                utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
     
    243256        head_ptr += strlen(head_ptr);
    244257    }
    245     if (log_host) {
     258    // Hostname should be 20 characters.
     259    if (p_psLogHost) {
    246260        if (head_ptr > head) {
    247261            *head_ptr++ = '|';
     
    250264        head_ptr += strlen(head_ptr);
    251265    }
    252     if (log_level) {
     266    if (p_psLogLevel) {
    253267        if (head_ptr > head) {
    254268            *head_ptr++ = '|';
     
    257271        head_ptr += strlen(head_ptr);
    258272    }
    259     if (log_name) {
     273    // The name field must be 15 characters.
     274    if (p_psLogName) {
    260275        if (head_ptr > head) {
    261276            *head_ptr++ = '|';
    262277        }
    263         sprintf(head_ptr, "%-15s", name);
     278        sprintf(head_ptr, "%15.15s", name);
    264279        head_ptr += strlen(head_ptr);
    265280    }
     
    270285    *head_ptr = '\0';
    271286
    272     switch (logDest) {
     287    switch (p_psGlobalLogDest) {
    273288    case PS_LOG_TO_STDOUT:
    274289        puts(head);
    275         if (log_msg) {
     290        if (p_psLogMsg) {
    276291            vprintf(fmt, ap);
    277292            if (fmt[strlen(fmt) - 1] != '\n') {
     
    285300    case PS_LOG_TO_STDERR:
    286301        fputs(head, stderr);
    287         if (log_msg) {
     302        if (p_psLogMsg) {
    288303            vfprintf(stderr, fmt, ap);
    289304            if (fmt[strlen(fmt) - 1] != '\n') {
  • trunk/psLib/src/sysUtils/psLogMsg.h

    r979 r1013  
     1/** @file  psLogMsg.h
     2 *  @brief Procedures for logging messages.
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedure which set
     6 *  message log levels, messahe log formats, message log destinations, and
     7 *  for generating the messages themselves.
     8 *  @ingroup LogTrace
     9 *
     10 *  @author Robert Lupton, Princeton University
     11 *  @author George Gusciora, MHPCC
     12 *
     13 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-06-12 05:50:01 $
     15 *
     16 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     17 */
    118#if !defined(PS_LOG_MSG_H)
    219#define PS_LOG_MSG_H
    3 
    4 /** \file psLogMsg.h
    5  *  \brief log messaging facilities
    6  *  \ingroup LogTrace
    7  */
    8 
    920#include <stdarg.h>
    1021
     
    1829/// In future versions, this procedure will take a character string as an
    1930/// argument which can specify more general log destinations.
    20 int psLogSetDestination(int dest);
     31int psLogSetDestination(int dest     ///< Specifies where to send messages.
     32                       );
     33
    2134
    2235/// This procedure sets the message level for future log messages.  Subsequent
     
    2538/// Ie. higher values set by this procedure will cause more log messages to
    2639/// be displayed.
    27 int psLogSetLevel(int level);
     40int psLogSetLevel(int level          ///< Specifies the system log level
     41                 );
     42
    2843
    2944/// This procedure sets the log format for future log messages.  The argument
     
    3247/// Deleting a letter from the string will cause the associated information
    3348/// to not be logged.
    34 void psLogSetFormat(const char *fmt);
     49void psLogSetFormat(const char *fmt ///< Specifies the system log format
     50                   );
    3551
    3652
     
    4157void psLogMsg(const char *name,     ///< name of the log source
    4258              int myLevel,          ///< severity level of this log message
    43               const char *fmt, ...) ///< printf-style format command
    44 ;
    45 
     59              const char *fmt, ...  ///< printf-style format command
     60             );
    4661
    4762
     
    5166               int myLevel,      ///< severity level of this log message
    5267               const char *fmt,  ///< printf-style format command
    53                va_list ap)       ///< varargs argument list
    54 ;
    55 
     68               va_list ap        ///< varargs argument list
     69              );
    5670
    5771///< Status codes for log messages
  • trunk/psLib/src/sysUtils/psTrace.c

    r928 r1013  
    1 /*****************************************************************************
    2     A simple implementation of a tracing facility for Pan-STARRS.  Tracing
    3     is controlled on a per "component" basis, where a "component" is a name
    4     of the form aaa.bbb.ccc where aaa is the most significant part.
    5  
     1/** @file psTrace.c
     2 *  \brief basic run-time trace facilities
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the code for procedures to insert
     6 *  trace messages into the code.
     7 *
     8 *  @author Robert Lupton, Princeton University
     9 *  @author George Gusciora, MHPCC
     10 *
     11 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-12 05:50:01 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
     16/*****************************************************************************
    617    NOTES:
    718 In the SRD, higher trace levels correspond to a numerically lower trace
     
    1627 trace level of that node.
    1728 
    18  This code is obfuscated by the fact that component names are of the form
    19  ".a.b.c.d" where "." is always the root of the tree, and for tree that have
    20  a depth of 3 or higher (including the root ".") the "."  character is also
    21  the deliminator between different individual nodes in the full component
    22  name.  So, for ".a.b.c.d", the first "." signifies the root of the tree,
    23  while the last three dots merely act as separators between the node names
    24  "b", "c", and "d".
    25  
    2629 I added a function psTraceFree() which frees all nodes in the trace component
    2730 tree.  Previously, there had been no function in the API which accomplished
     
    3235#include <string.h>
    3336#include <stdarg.h>
    34 /* #include "pslib.h" */
    3537#include "psMemory.h"
    3638#include "psTrace.h"
     
    3840#include "psError.h"
    3941
    40 static Component *croot = NULL;           // The root of the trace component
    41 static FILE *traceFP = NULL;
    42 /*****************************************************************************
    43     componentAlloc(): allocate memory for a new node, and initialize members.
     42static Component *p_psCroot = NULL;       // The root of the trace component
     43static FILE *p_psTraceFP = NULL;          // File destination for messages.
     44/*****************************************************************************
     45componentAlloc(): allocate memory for a new node, and initialize members.
    4446 *****************************************************************************/
    4547Component *componentAlloc(const char *name,
     
    5658
    5759/*****************************************************************************
    58     componentFree(): free the current node in the root tree, and all
    59  children nodes as well.
     60componentFree(): free the current node in the root tree, and all children
     61nodes as well.
    6062 *****************************************************************************/
    6163static void componentFree(Component *comp)
     
    7880
    7981/*****************************************************************************
    80     initTrace(): simply initialize the component root tree.
     82initTrace(): simply initialize the component root tree.
    8183*****************************************************************************/
    8284static void initTrace(void)
    8385{
    84     if (croot == NULL) {
    85         croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
    86     }
    87 }
    88 
    89 
    90 /*****************************************************************************
    91     Set all trace levels to zero.
     86    if (p_psCroot == NULL) {
     87        p_psCroot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
     88    }
     89}
     90
     91
     92/*****************************************************************************
     93Set all trace levels to zero.
    9294 *****************************************************************************/
    9395void p_psTraceReset(Component *currentNode)
     
    112114}
    113115
     116/*****************************************************************************
     117Set all trace levels to zero.
     118 *****************************************************************************/
    114119void psTraceReset()
    115120{
    116     p_psTraceReset(croot);
    117 }
    118 
    119 
     121    p_psTraceReset(p_psCroot);
     122}
     123
     124
     125/*****************************************************************************
     126Free all nodes in the component tree.
     127 *****************************************************************************/
    120128void psTraceFree()
    121129{
    122     componentFree(croot);
    123 }
    124 
    125 
    126 /*****************************************************************************
    127     componentAdd(): Adds the component named "addNodeName" to the root tree.
     130    componentFree(p_psCroot);
     131}
     132
     133
     134/*****************************************************************************
     135componentAdd(): Adds the component named "addNodeName" to the root tree.
    128136 
    129     NOTE: replace the call to strsep() with a call to strtok(), which conforms
    130     to ANSI-C.
     137NOTE: replace the call to strsep() with a call to strtok(), which conforms
     138to ANSI-C.
    131139 *****************************************************************************/
    132140static void componentAdd(const char *addNodeName,
    133141                         int         level)
    134142{
    135     int        i = 0;
    136     char       name[strlen(addNodeName) + 1];
    137     // buffer for writeable copy.
     143    int        i = 0;                         // Loop index variable.
     144    char       name[strlen(addNodeName) + 1]; // buffer for writeable copy.
    138145    char      *pname=name;
    139146    char      *firstComponent = NULL;       // first component of name
    140     Component *currentNode = croot;
     147    Component *currentNode = p_psCroot;
    141148    int        nodeExists = 0;
    142149
    143150    // Is this the root node?  If so, simply set level and return.
    144151    if (strcmp(".", addNodeName) == 0) {
    145         croot->level = level;
     152        p_psCroot->level = level;
    146153        return;
    147154    }
     
    199206{
    200207    // If the root component tree does not exist, then initialize it.
    201     if (croot == NULL) {
     208    if (p_psCroot == NULL) {
    202209        initTrace();
    203210    }
     
    230237    char      *pname=name;
    231238    char      *firstComponent = NULL;   // first component of name
    232     Component *currentNode = croot;
     239    Component *currentNode = p_psCroot;
    233240    int        i = 0;
    234241
     
    238245
    239246    if (strcmp(".", aname) == 0) {
    240         return(croot->level);
     247        return(p_psCroot->level);
    241248    }
    242249
     
    282289int psTraceGetLevel(const char *name)
    283290{
    284     if (croot == NULL) {
     291    if (p_psCroot == NULL) {
    285292        return(UNKNOWN_TRACE_LEVEL);
    286293    }
     
    328335
    329336/*****************************************************************************
    330     psPrintTraceLevels()
    331  Simply print all the trace levels in the trace level component tree.
    332     Inputs:
    333  none
    334     Outputs:
    335  none
    336     Returns:
     337psPrintTraceLevels(): Simply print all the trace levels in the trace level
     338component tree.
     339Inputs:
     340 none
     341Outputs:
     342 none
     343Returns:
    337344 null
    338345*****************************************************************************/
    339346void psTracePrintLevels(void)
    340347{
    341     if (croot == NULL) {
     348    if (p_psCroot == NULL) {
    342349        return;
    343350    }
    344351
    345     doPrintTraceLevels(croot, 0);
    346 }
    347 
    348 
    349 /*****************************************************************************
    350     p_psTrace(): we display the trace message to standard output if the trace
    351  level of that message, supplied by the parameter "level" is higher
    352  than the trace level that is currently associated with the component
    353  named by the parameter "comp".
    354     Input:
     352    doPrintTraceLevels(p_psCroot, 0);
     353}
     354
     355
     356/*****************************************************************************
     357p_psTrace(): we display the trace message to standard output if the trace
     358level of that message, supplied by the parameter "level" is higher than the
     359trace level that is currently associated with the component named by the
     360parameter "comp".
     361Input:
    355362 comp
    356363 level
    357364 ...  a printf-style output string.
    358     Output:
    359  none
    360     Return:
     365Output:
     366 none
     367Return:
    361368 null
    362369 *****************************************************************************/
     
    384391        fmt = va_arg(ap, char *);
    385392
    386         if (traceFP != NULL) {
     393        if (p_psTraceFP != NULL) {
    387394            // We indent each message one space for each level of the message.
    388395            for (i = 0; i < level; i++) {
    389                 fprintf(traceFP, " ");
     396                fprintf(p_psTraceFP, " ");
    390397            }
    391             vfprintf(traceFP, fmt, ap);
     398            vfprintf(p_psTraceFP, fmt, ap);
    392399        } else {
    393400            // We indent each message one space for each level of the message.
     
    405412void psTraceSetDestination(FILE *fp)
    406413{
    407     traceFP = fp;
    408 }
     414    p_psTraceFP = fp;
     415}
  • trunk/psLib/src/sysUtils/psTrace.h

    r978 r1013  
     1/** @file psTrace.h
     2 *  \brief basic run-time trace facilities
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the prototypes for defining procedures to insert
     6 *  trace messages into the code.
     7 *
     8 *  @author Robert Lupton, Princeton University
     9 *  @author George Gusciora, MHPCC
     10 *
     11 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-12 05:50:01 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
    116#if !defined(PS_TRACE_H)
    217#define PS_TRACE_H 1
     
    419#define DEFAULT_TRACE_LEVEL 0
    520
    6 /** \file psTrace.h
    7  *  \brief basic run-time trace facilities
    8  *  \ingroup LogTrace
    9  */
    10 
    11 /*****************************************************************************
    12     A component is a string of the form aaa.bbb.ccc, and may itself contain
    13     further subcomponents.  The Component structure doesn't in fact contain
    14     it's full name, but only the last part.
    15  *****************************************************************************/
     21/** Basic structure for the component tree.  A component is a string of the
     22    form aaa.bbb.ccc, and may itself contain further subcomponents.  The
     23    Component structure doesn't in fact contain it's full name, but only the
     24    last part. */
    1625typedef struct Component
    1726{
     
    2635 *  \{
    2736 */
    28 
    2937
    3038/** Functions **************************************************************/
     
    5967;
    6068
     69/// Set the destination of future trace messages.
    6170void psTraceSetDestination(FILE *fp);
    6271
Note: See TracChangeset for help on using the changeset viewer.