[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Come up with a less macro-happy, even more portable log_fn ...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv15703/src/common

Modified Files:
	log.c log.h 
Log Message:
Come up with a less macro-happy, even more portable log_fn implementation

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- log.c	19 Mar 2003 20:54:39 -0000	1.5
+++ log.c	17 Jun 2003 21:36:44 -0000	1.6
@@ -42,36 +42,50 @@
   return strlen(buf)+1;
 }
 
-/* Outputs a message to stdout */
-void log(int severity, const char *format, ...)
+static void 
+logv(int severity, const char *funcname, const char *format, va_list ap)
 {
   static int loglevel = LOG_DEBUG;
   char buf[201];
   time_t t;
-  va_list ap;
   struct timeval now;
-
+  
   if (format) {
 
-    if(gettimeofday(&now,NULL) < 0)
+    if (severity > loglevel)
+      return;
+    if (gettimeofday(&now,NULL) < 0)
       return;
 
-    va_start(ap,format);
-  
-    if (severity <= loglevel)
-    {
-      t = time(NULL);
-      strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t));
-      printf("%s.%.3ld ", buf, (long)now.tv_usec / 1000);
-      sev_to_string(buf, 200, severity);
-      printf("[%s] ", buf);
-      vprintf(format,ap);
-      printf("\n");
-    }
-    
-    va_end(ap);
-  }
-  else
+    t = time(NULL);
+    strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t));
+    printf("%s.%.3ld ", buf, (long)now.tv_usec / 1000);
+    sev_to_string(buf, 200, severity);
+    printf("[%s] ", buf);
+    if (funcname)
+      printf("%s(): ", funcname);
+    vprintf(format,ap);
+    printf("\n");
+  } else
     loglevel = severity;
+
+}
+
+/* Outputs a message to stdout */
+void log(int severity, const char *format, ...)
+{
+  va_list ap;
+  va_start(ap,format);
+  logv(severity, NULL, format, ap);
+  va_end(ap);
+}
+
+void _log_fn(int severity, const char *fn, const char *format, ...)
+{
+  va_list ap;
+  va_start(ap,format);
+  logv(severity, fn, format, ap);
+  va_end(ap);
 }
+
 

Index: log.h
===================================================================
RCS file: /home/or/cvsroot/src/common/log.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- log.h	17 Jun 2003 21:15:25 -0000	1.7
+++ log.h	17 Jun 2003 21:36:44 -0000	1.8
@@ -13,16 +13,11 @@
 void log(int severity, const char *format, ...);
 
 #ifdef __GNUC__
-#ifdef __APPLE_CPP__
+void _log_fn(int severity, const char *funcname, const char *format, ...);
 #define log_fn(severity, args...) \
-  log((severity), __PRETTY_FUNCTION__ "(): " args)
-#else
-#define log_fn(severity, format, args...) \
-  log((severity), "%s(): " format, __PRETTY_FUNCTION__ , ##args)
-#endif
+  _log_fn(severity, __PRETTY_FUNCTION__, args)
 #else
 #define log_fn log
-#define log_fnf log
 #endif
 
 # define __LOG_H