Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In RL, count the time from the begining of the application, not from the 1 jan 1970...
[simgrid.git] / src / xbt / log_default_appender.c
index 28c5f36..7aeb170 100644 (file)
@@ -2,16 +2,16 @@
 
 /* file_appender - a dumb log appender which simply prints to stdout        */
 
-/* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
 
 /* This program is free software; you can redistribute it and/or modify it
  under the terms of the license (GNU LGPL) which comes with this package. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
 #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");
 
@@ -36,13 +36,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) %g", 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;
     
@@ -52,9 +72,9 @@ static void append_file(xbt_log_appender_t this,
                 "Priority %d is greater than the biggest allowed value",
                 ev->priority);
 
-    fprintf(stderr, "%s:%d: ", 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]);
+           ev->cat->name, xbt_log_priority_names[ev->priority] );
     vfprintf(stderr, fmt, ev->ap);
     fprintf(stderr, "\n");
 }