[openib-general] OpenSM Log Message Format

Hal Rosenstock halr at voltaire.com
Wed Jan 12 06:05:28 PST 2005


Hi,

Should date/time format be used rather than timeval when OSM logs
messages ? That would make the messages more like the other daemons.
Here's a proposed patch to do this.

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

-- Hal
Index: osm_log.c
===================================================================
--- osm_log.c	(revision 1519)
+++ osm_log.c	(working copy)
@@ -96,6 +96,23 @@
 #include <unistd.h>
 #endif
 
+#ifndef WIN32
+static char *month_str[] = {
+  "Jan",
+  "Feb",
+  "Mar",
+  "Apr",
+  "May",
+  "Jun",
+  "Jul",
+  "Aug",
+  "Sep",
+  "Oct",
+  "Nov",
+  "Dec"
+};
+#endif
+
 void
 osm_log(
   IN osm_log_t* const p_log,
@@ -111,8 +128,8 @@
   uint32_t pid = GetCurrentThreadId();
 #else
   pid_t pid;
-  struct timeval tv;
-  struct timezone tz;
+  time_t tim;
+  struct tm result;
 #endif /*  WIN32 */
 
   /* If this is a call to syslog - always print it */
@@ -152,9 +169,12 @@
       
 #else
       pid = pthread_self();
-      gettimeofday( &tv, &tz );
-      ret = fprintf( p_log->out_port, "[%09ld:%09ld][%04X] -> %s",
-                     tv.tv_sec, (long)tv.tv_usec,
+      tim = time(NULL);
+      localtime_r(&tim, &result);
+      ret = fprintf( p_log->out_port, "%s %02d %02d:%02d:%02d [%04X] -> %s",
+                    (result.tm_mon < 12 ? month_str[result.tm_mon] : "???"),
+                     result.tm_mday, result.tm_hour,
+                     result.tm_min, result.tm_sec,
                      pid, buffer);
 #endif /*  WIN32 */
       






More information about the general mailing list