Index: trunk/psLib/src/sysUtils/psLogMsg.c
===================================================================
--- trunk/psLib/src/sysUtils/psLogMsg.c	(revision 979)
+++ trunk/psLib/src/sysUtils/psLogMsg.c	(revision 1013)
@@ -1,13 +1,29 @@
-/*****************************************************************************
-    A simple implementation of a logging facility for Pan-STARRS
- 
+/** @file  psLogMsg.c
+ *  @brief Procedures for logging messages.
+ *  \ingroup LogTrace
+ *
+ *  This file will hold the prototypes for defining procedure which set
+ *  message log levels, messahe log formats, message log destinations, and
+ *  for generating the messages themselves.
+ *  @ingroup LogTrace
+ *
+ *  @author Robert Lupton, Princeton University
+ *  @author George Gusciora, MHPCC
+ *
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-12 05:50:01 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+/*****************************************************************************
 NOTES: currently, the prototype code has the following global variables:
-    static int logDest;
-    static int logLevel;
-    static int log_time;
-    static int log_host;
-    static int log_level;
-    static int log_name;
-    static int log_msg;
+    static int p_psGlobalLogDest;
+    static int p_psGlobalLogLevel;
+    static int p_psLogTime;
+    static int p_psLogHost;
+    static int p_psLogLevel;
+    static int p_psLogName;
+    static int p_psLogMsg;
  *****************************************************************************/
 #include <limits.h>
@@ -18,6 +34,4 @@
 #include <time.h>
 #include <unistd.h>
-
-/* #include "psLib.h" */
 #include "psLogMsg.h"
 #include "psError.h"
@@ -27,15 +41,15 @@
 #define MIN_LOG_LEVEL 0
 #define MAX_LOG_LEVEL 9
-static int logDest = PS_LOG_TO_STDERR; // where to log messages
-static int logLevel = PS_LOG_INFO;     // log all messages at this or above
+static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages
+static int p_psGlobalLogLevel = PS_LOG_INFO;     // log all messages at this or above
 //static FILE *p_logFP = NULL;
 // The following variables control
 // which information is displayed in
 // log messages.
-static int log_time = 1;                // Flag to include time info
-static int log_host = 1;                // Flag to include host info
-static int log_level = 1;               // Flag to include level info
-static int log_name = 1;                // Flag to include name info
-static int log_msg = 1;                 // Flag to include message info
+static int p_psLogTime = 1;                // Flag to include time info
+static int p_psLogHost = 1;                // Flag to include host info
+static int p_psLogLevel = 1;               // Flag to include level info
+static int p_psLogName = 1;                // Flag to include name info
+static int p_psLogMsg = 1;                 // Flag to include message info
 /*****************************************************************************
 psLogSetLevel(): Set the current log level and return old level.
@@ -49,5 +63,6 @@
 int psLogSetLevel(int level)
 {
-    int oldLevel = logLevel;
+    // Save old global log level for changing it.
+    int oldLevel = p_psGlobalLogLevel;
 
     if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) {
@@ -57,5 +72,8 @@
     }
 
-    logLevel = level;
+    // Set new global log level
+    p_psGlobalLogLevel = level;
+
+    // Return old global log level
     return oldLevel;
 }
@@ -75,5 +93,6 @@
 int psLogSetDestination(int dest)
 {
-    int old = logDest;
+    // Save old global log destination before changing it.
+    int old = p_psGlobalLogDest;
 
     switch (dest) {
@@ -81,13 +100,15 @@
     case PS_LOG_TO_STDOUT:
     case PS_LOG_TO_STDERR:
-        logDest = dest;
+        // Set new global log destination
+        p_psGlobalLogDest = dest;
         break;
 
     default:
         // GUS: Should you log this error properly?
-        fprintf(stderr,"Unknown logDestination: %d (ignored)\n", dest);
-        break;
-    }
-
+        fprintf(stderr,"Unknown p_psGlobalLogDest: %d (ignored)\n", dest);
+        break;
+    }
+
+    // Return old global log destination
     return old;
 }
@@ -112,9 +133,7 @@
 void psLogSetFormat(const char *fmt)
 {
-    int nlog_time = 0;
-    int nlog_host = 0;
-    int nlog_level = 0;
-    int nlog_name = 0;
-    int nlog_msg = 0;
+
+    // Step through each character in the format string.  For each letter
+    // in that string, set/unset the appropriate logging.
 
     for (const char *ptr = fmt; *ptr != '\0'; ptr++) {
@@ -122,26 +141,23 @@
         case 'H':
         case 'h':
-            nlog_host = 1;
+            p_psLogHost = 1;
             break;
         case 'L':
         case 'l':
-            nlog_level = 1;
+            p_psLogLevel = 1;
             break;
         case 'M':
         case 'm':
-            nlog_msg = 1;
+            p_psLogMsg = 1;
             break;
         case 'N':
         case 'n':
-            nlog_name = 1;
+            p_psLogName = 1;
             break;
         case 'T':
         case 't':
-            nlog_time = 1;
+            p_psLogTime = 1;
             break;
         default:
-            // GUS: figure out the psError() format:
-            //     psError(__func__, PS_ERR_UNKNOWN, 1,
-            //            "Unknown logging keyword %c", *ptr);
             psError(__func__, "Unknown logging keyword %c", *ptr);
             break;
@@ -149,15 +165,9 @@
     }
 
-    if (!nlog_msg) {
+    if (!p_psLogMsg) {
         psTrace("utils.logMsg", 1,
                 "You must at least log error messages (You chose \"%s\")",
                 fmt);
     }
-
-    log_host = nlog_host;
-    log_level = nlog_level;
-    log_msg = nlog_msg;
-    log_name = nlog_name;
-    log_time = nlog_time;
 }
 
@@ -186,16 +196,19 @@
                va_list ap)
 {
-    static int first = 1;
+    static int first = 1;               // Flag for calling gethostname()
     static char hostname[HOST_NAME_MAX + 1];
+    // Buffer for hostname.
     char clevel=0;                      // letter-name for level
     char head[HOST_NAME_MAX + 40];      // yes, this is long enough
     char *head_ptr = head;              // where we've got to in head
-    time_t clock = time(NULL);
-    struct tm *utc = gmtime(&clock);
-
-    if ((level > logLevel) || (logDest == PS_LOG_NONE)) {
+    time_t clock = time(NULL);          // The current time.
+    struct tm *utc = gmtime(&clock);    // The current gm time.
+
+    // If logging is off, or if the level is too high, return immediately.
+    if ((level > p_psGlobalLogLevel) || (p_psGlobalLogDest == PS_LOG_NONE)) {
         return;
     }
 
+    // If I have not been here yet, determine my hostname and save it.
     if (first) {
         first = 0;
@@ -236,6 +249,6 @@
     }
 
-
-    if (log_time) {
+    // Create the various log fields...
+    if (p_psLogTime) {
         sprintf(head_ptr, "%4d:%02d:%02d %02d:%02d:%02dZ",
                 utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
@@ -243,5 +256,6 @@
         head_ptr += strlen(head_ptr);
     }
-    if (log_host) {
+    // Hostname should be 20 characters.
+    if (p_psLogHost) {
         if (head_ptr > head) {
             *head_ptr++ = '|';
@@ -250,5 +264,5 @@
         head_ptr += strlen(head_ptr);
     }
-    if (log_level) {
+    if (p_psLogLevel) {
         if (head_ptr > head) {
             *head_ptr++ = '|';
@@ -257,9 +271,10 @@
         head_ptr += strlen(head_ptr);
     }
-    if (log_name) {
+    // The name field must be 15 characters.
+    if (p_psLogName) {
         if (head_ptr > head) {
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%-15s", name);
+        sprintf(head_ptr, "%15.15s", name);
         head_ptr += strlen(head_ptr);
     }
@@ -270,8 +285,8 @@
     *head_ptr = '\0';
 
-    switch (logDest) {
+    switch (p_psGlobalLogDest) {
     case PS_LOG_TO_STDOUT:
         puts(head);
-        if (log_msg) {
+        if (p_psLogMsg) {
             vprintf(fmt, ap);
             if (fmt[strlen(fmt) - 1] != '\n') {
@@ -285,5 +300,5 @@
     case PS_LOG_TO_STDERR:
         fputs(head, stderr);
-        if (log_msg) {
+        if (p_psLogMsg) {
             vfprintf(stderr, fmt, ap);
             if (fmt[strlen(fmt) - 1] != '\n') {
