Changeset 1141
- Timestamp:
- Jun 29, 2004, 3:58:20 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 2 edited
-
sys/psLogMsg.c (modified) (11 diffs)
-
sysUtils/psLogMsg.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psLogMsg.c
r1138 r1141 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1.1 7$ $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 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 #include <time.h> 35 35 #include <unistd.h> 36 #include <stdbool.h> 37 36 38 #include "psLogMsg.h" 37 39 #include "psError.h" … … 41 43 #define MIN_LOG_LEVEL 0 42 44 #define MAX_LOG_LEVEL 9 45 46 #define MAX_LOG_LINE_LENGTH 128 43 47 static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages 44 48 static int p_psGlobalLogLevel = PS_LOG_INFO; // log all messages at this or above … … 47 51 // which information is displayed in 48 52 // log messages. 49 static int p_psLogTime = 1;// Flag to include time info50 static int p_psLogHost = 1;// Flag to include host info51 static int p_psLogLevel = 1;// Flag to include level info52 static int p_psLogName = 1;// Flag to include name info53 static int p_psLogMsg = 1;// Flag to include message info53 static bool p_psLogTime = true; // Flag to include time info 54 static bool p_psLogHost = true; // Flag to include host info 55 static bool p_psLogLevel = true; // Flag to include level info 56 static bool p_psLogName = true; // Flag to include name info 57 static bool p_psLogMsg = true; // Flag to include message info 54 58 /***************************************************************************** 55 59 psLogSetLevel(): Set the current log level and return old level. … … 133 137 void psLogSetFormat(const char *fmt) 134 138 { 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 } 135 150 136 151 // Step through each character in the format string. For each letter … … 141 156 case 'H': 142 157 case 'h': 143 p_psLogHost = 1;158 p_psLogHost = true; 144 159 break; 145 160 case 'L': 146 161 case 'l': 147 p_psLogLevel = 1;162 p_psLogLevel = true; 148 163 break; 149 164 case 'M': 150 165 case 'm': 151 p_psLogMsg = 1;166 p_psLogMsg = true; 152 167 break; 153 168 case 'N': 154 169 case 'n': 155 p_psLogName = 1;170 p_psLogName = true; 156 171 break; 157 172 case 'T': 158 173 case 't': 159 p_psLogTime = 1;174 p_psLogTime = true; 160 175 break; 161 176 default: … … 200 215 // Buffer for hostname. 201 216 char clevel=0; // letter-name for level 202 char head[ HOST_NAME_MAX + 40]; // yes, this is long enough217 char head[MAX_LOG_LINE_LENGTH+2]; // the added two are for the ending | and \0 203 218 char *head_ptr = head; // where we've got to in head 219 int maxLength = MAX_LOG_LINE_LENGTH; 204 220 time_t clock = time(NULL); // The current time. 205 221 struct tm *utc = gmtime(&clock); // The current gm time. … … 251 267 // Create the various log fields... 252 268 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; 256 272 head_ptr += strlen(head_ptr); 257 273 } … … 261 277 *head_ptr++ = '|'; 262 278 } 263 sprintf(head_ptr, "%-20s", hostname);279 maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname); 264 280 head_ptr += strlen(head_ptr); 265 281 } … … 268 284 *head_ptr++ = '|'; 269 285 } 270 sprintf(head_ptr, "%c", clevel);286 maxLength -= snprintf(head_ptr, maxLength, "%c", clevel); 271 287 head_ptr += strlen(head_ptr); 272 288 } … … 276 292 *head_ptr++ = '|'; 277 293 } 278 sprintf(head_ptr, "%15.15s", name);294 maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name); 279 295 head_ptr += strlen(head_ptr); 280 296 } -
trunk/psLib/src/sysUtils/psLogMsg.c
r1138 r1141 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1.1 7$ $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 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 #include <time.h> 35 35 #include <unistd.h> 36 #include <stdbool.h> 37 36 38 #include "psLogMsg.h" 37 39 #include "psError.h" … … 41 43 #define MIN_LOG_LEVEL 0 42 44 #define MAX_LOG_LEVEL 9 45 46 #define MAX_LOG_LINE_LENGTH 128 43 47 static int p_psGlobalLogDest = PS_LOG_TO_STDERR; // where to log messages 44 48 static int p_psGlobalLogLevel = PS_LOG_INFO; // log all messages at this or above … … 47 51 // which information is displayed in 48 52 // log messages. 49 static int p_psLogTime = 1;// Flag to include time info50 static int p_psLogHost = 1;// Flag to include host info51 static int p_psLogLevel = 1;// Flag to include level info52 static int p_psLogName = 1;// Flag to include name info53 static int p_psLogMsg = 1;// Flag to include message info53 static bool p_psLogTime = true; // Flag to include time info 54 static bool p_psLogHost = true; // Flag to include host info 55 static bool p_psLogLevel = true; // Flag to include level info 56 static bool p_psLogName = true; // Flag to include name info 57 static bool p_psLogMsg = true; // Flag to include message info 54 58 /***************************************************************************** 55 59 psLogSetLevel(): Set the current log level and return old level. … … 133 137 void psLogSetFormat(const char *fmt) 134 138 { 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 } 135 150 136 151 // Step through each character in the format string. For each letter … … 141 156 case 'H': 142 157 case 'h': 143 p_psLogHost = 1;158 p_psLogHost = true; 144 159 break; 145 160 case 'L': 146 161 case 'l': 147 p_psLogLevel = 1;162 p_psLogLevel = true; 148 163 break; 149 164 case 'M': 150 165 case 'm': 151 p_psLogMsg = 1;166 p_psLogMsg = true; 152 167 break; 153 168 case 'N': 154 169 case 'n': 155 p_psLogName = 1;170 p_psLogName = true; 156 171 break; 157 172 case 'T': 158 173 case 't': 159 p_psLogTime = 1;174 p_psLogTime = true; 160 175 break; 161 176 default: … … 200 215 // Buffer for hostname. 201 216 char clevel=0; // letter-name for level 202 char head[ HOST_NAME_MAX + 40]; // yes, this is long enough217 char head[MAX_LOG_LINE_LENGTH+2]; // the added two are for the ending | and \0 203 218 char *head_ptr = head; // where we've got to in head 219 int maxLength = MAX_LOG_LINE_LENGTH; 204 220 time_t clock = time(NULL); // The current time. 205 221 struct tm *utc = gmtime(&clock); // The current gm time. … … 251 267 // Create the various log fields... 252 268 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; 256 272 head_ptr += strlen(head_ptr); 257 273 } … … 261 277 *head_ptr++ = '|'; 262 278 } 263 sprintf(head_ptr, "%-20s", hostname);279 maxLength -= snprintf(head_ptr, maxLength, "%-20s", hostname); 264 280 head_ptr += strlen(head_ptr); 265 281 } … … 268 284 *head_ptr++ = '|'; 269 285 } 270 sprintf(head_ptr, "%c", clevel);286 maxLength -= snprintf(head_ptr, maxLength, "%c", clevel); 271 287 head_ptr += strlen(head_ptr); 272 288 } … … 276 292 *head_ptr++ = '|'; 277 293 } 278 sprintf(head_ptr, "%15.15s", name);294 maxLength -= snprintf(head_ptr, maxLength, "%15.15s", name); 279 295 head_ptr += strlen(head_ptr); 280 296 }
Note:
See TracChangeset
for help on using the changeset viewer.
