Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
moved to %f instead of %g. It's usefull when values get large...
[simgrid.git] / src / xbt / log_default_appender.c
index 871001e..4094303 100644 (file)
@@ -9,8 +9,8 @@
 
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
-#include "xbt/error.h"
 #include <stdio.h>
+#include "gras/virtu.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log,"default logging handler");
 
@@ -35,13 +35,33 @@ static s_xbt_log_appender_t xbt_log_appender_file = { append_file, NULL } ;
 
 xbt_log_appender_t xbt_log_default_appender  = &xbt_log_appender_file;
 
+static const char* xbt_logappender_verbose_information(void) {
+  static char buffer[256];
+  static double begin_of_time = -1;
+  
+  if (begin_of_time<0) 
+    begin_of_time=gras_os_time();
+
+  if(strlen(xbt_procname()))
+    sprintf(buffer,"%s:%s:(%d) %f", gras_os_myname(),
+           xbt_procname(),gras_os_getpid(),gras_os_time()-begin_of_time);
+  else 
+    buffer[0]=0;
+  
+  return buffer;
+}
+
 static void append_file(xbt_log_appender_t this,
                        xbt_log_event_t ev, 
                        const char *fmt) {
 
   /* TODO: define a format field in struct for timestamp, etc.
      struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0;*/
-    
+
+  char *procname = (char*)xbt_logappender_verbose_information();
+  if (!procname) 
+     procname = (char*)"";
+   
     if ((FILE*)(this->appender_data) == NULL)
       this->appender_data = (void*)stderr;
     
@@ -51,7 +71,7 @@ static void append_file(xbt_log_appender_t this,
                 "Priority %d is greater than the biggest allowed value",
                 ev->priority);
 
-    fprintf(stderr, "[%s] %s:%d: ", xbt_procname(), ev->fileName, ev->lineNum);
+    fprintf(stderr, "[%s] %s:%d: ", procname, ev->fileName, ev->lineNum);
     fprintf(stderr, "[%s/%s] ", 
            ev->cat->name, xbt_log_priority_names[ev->priority] );
     vfprintf(stderr, fmt, ev->ap);