Index: /trunk/psLib/src/sys/psLogMsg.c
===================================================================
--- /trunk/psLib/src/sys/psLogMsg.c	(revision 1140)
+++ /trunk/psLib/src/sys/psLogMsg.c	(revision 1141)
@@ -11,6 +11,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-30 01:17:20 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-30 01:58:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,4 +34,6 @@
 #include <time.h>
 #include <unistd.h>
+#include <stdbool.h>
+
 #include "psLogMsg.h"
 #include "psError.h"
@@ -41,4 +43,6 @@
 #define MIN_LOG_LEVEL 0
 #define MAX_LOG_LEVEL 9
+
+#define MAX_LOG_LINE_LENGTH 128
 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
@@ -47,9 +51,9 @@
 // which information is displayed in
 // log messages.
-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
+static bool p_psLogTime = true;        // Flag to include time info
+static bool p_psLogHost = true;        // Flag to include host info
+static bool p_psLogLevel = true;       // Flag to include level info
+static bool p_psLogName = true;        // Flag to include name info
+static bool p_psLogMsg = true;         // Flag to include message info
 /*****************************************************************************
 psLogSetLevel(): Set the current log level and return old level.
@@ -133,4 +137,15 @@
 void psLogSetFormat(const char *fmt)
 {
+    // assume nothing desired unless specified
+    p_psLogHost = false;
+    p_psLogLevel = false;
+    p_psLogMsg = false;
+    p_psLogName = false;
+    p_psLogTime = false;
+
+    // if fmt is NULL, no logging is desired.
+    if (fmt == NULL) {
+        return;
+    }
 
     // Step through each character in the format string.  For each letter
@@ -141,21 +156,21 @@
         case 'H':
         case 'h':
-            p_psLogHost = 1;
+            p_psLogHost = true;
             break;
         case 'L':
         case 'l':
-            p_psLogLevel = 1;
+            p_psLogLevel = true;
             break;
         case 'M':
         case 'm':
-            p_psLogMsg = 1;
+            p_psLogMsg = true;
             break;
         case 'N':
         case 'n':
-            p_psLogName = 1;
+            p_psLogName = true;
             break;
         case 'T':
         case 't':
-            p_psLogTime = 1;
+            p_psLogTime = true;
             break;
         default:
@@ -200,6 +215,7 @@
     // Buffer for hostname.
     char clevel=0;                      // letter-name for level
-    char head[HOST_NAME_MAX + 40];      // yes, this is long enough
+    char head[MAX_LOG_LINE_LENGTH+2];   // the added two are for the ending | and \0
     char *head_ptr = head;              // where we've got to in head
+    int maxLength = MAX_LOG_LINE_LENGTH;
     time_t clock = time(NULL);          // The current time.
     struct tm *utc = gmtime(&clock);    // The current gm time.
@@ -251,7 +267,7 @@
     // 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,
-                utc->tm_hour, utc->tm_min, utc->tm_sec);
+        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
+                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
+                              utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
         head_ptr += strlen(head_ptr);
     }
@@ -261,5 +277,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%-20s", hostname);
+        maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname);
         head_ptr += strlen(head_ptr);
     }
@@ -268,5 +284,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%c", clevel);
+        maxLength -= snprintf(head_ptr, maxLength, "%c", clevel);
         head_ptr += strlen(head_ptr);
     }
@@ -276,5 +292,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%15.15s", name);
+        maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name);
         head_ptr += strlen(head_ptr);
     }
Index: /trunk/psLib/src/sysUtils/psLogMsg.c
===================================================================
--- /trunk/psLib/src/sysUtils/psLogMsg.c	(revision 1140)
+++ /trunk/psLib/src/sysUtils/psLogMsg.c	(revision 1141)
@@ -11,6 +11,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-30 01:17:20 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-30 01:58:20 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,4 +34,6 @@
 #include <time.h>
 #include <unistd.h>
+#include <stdbool.h>
+
 #include "psLogMsg.h"
 #include "psError.h"
@@ -41,4 +43,6 @@
 #define MIN_LOG_LEVEL 0
 #define MAX_LOG_LEVEL 9
+
+#define MAX_LOG_LINE_LENGTH 128
 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
@@ -47,9 +51,9 @@
 // which information is displayed in
 // log messages.
-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
+static bool p_psLogTime = true;        // Flag to include time info
+static bool p_psLogHost = true;        // Flag to include host info
+static bool p_psLogLevel = true;       // Flag to include level info
+static bool p_psLogName = true;        // Flag to include name info
+static bool p_psLogMsg = true;         // Flag to include message info
 /*****************************************************************************
 psLogSetLevel(): Set the current log level and return old level.
@@ -133,4 +137,15 @@
 void psLogSetFormat(const char *fmt)
 {
+    // assume nothing desired unless specified
+    p_psLogHost = false;
+    p_psLogLevel = false;
+    p_psLogMsg = false;
+    p_psLogName = false;
+    p_psLogTime = false;
+
+    // if fmt is NULL, no logging is desired.
+    if (fmt == NULL) {
+        return;
+    }
 
     // Step through each character in the format string.  For each letter
@@ -141,21 +156,21 @@
         case 'H':
         case 'h':
-            p_psLogHost = 1;
+            p_psLogHost = true;
             break;
         case 'L':
         case 'l':
-            p_psLogLevel = 1;
+            p_psLogLevel = true;
             break;
         case 'M':
         case 'm':
-            p_psLogMsg = 1;
+            p_psLogMsg = true;
             break;
         case 'N':
         case 'n':
-            p_psLogName = 1;
+            p_psLogName = true;
             break;
         case 'T':
         case 't':
-            p_psLogTime = 1;
+            p_psLogTime = true;
             break;
         default:
@@ -200,6 +215,7 @@
     // Buffer for hostname.
     char clevel=0;                      // letter-name for level
-    char head[HOST_NAME_MAX + 40];      // yes, this is long enough
+    char head[MAX_LOG_LINE_LENGTH+2];   // the added two are for the ending | and \0
     char *head_ptr = head;              // where we've got to in head
+    int maxLength = MAX_LOG_LINE_LENGTH;
     time_t clock = time(NULL);          // The current time.
     struct tm *utc = gmtime(&clock);    // The current gm time.
@@ -251,7 +267,7 @@
     // 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,
-                utc->tm_hour, utc->tm_min, utc->tm_sec);
+        maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ",
+                              utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday,
+                              utc->tm_hour, utc->tm_min, utc->tm_sec)-1;
         head_ptr += strlen(head_ptr);
     }
@@ -261,5 +277,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%-20s", hostname);
+        maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname);
         head_ptr += strlen(head_ptr);
     }
@@ -268,5 +284,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%c", clevel);
+        maxLength -= snprintf(head_ptr, maxLength, "%c", clevel);
         head_ptr += strlen(head_ptr);
     }
@@ -276,5 +292,5 @@
             *head_ptr++ = '|';
         }
-        sprintf(head_ptr, "%15.15s", name);
+        maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name);
         head_ptr += strlen(head_ptr);
     }
