Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change mmalloc.h into a public header
[simgrid.git] / src / xbt / xbt_log_layout_format.c
index 9936400..0baafcb 100644 (file)
@@ -1,8 +1,7 @@
-/* $Id$ */
-
 /* layout_simple - a dumb log layout                                        */
 
-/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * 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. */
@@ -15,9 +14,9 @@
 #include "xbt/synchro.h"        /* xbt_thread_self_name */
 #include <stdio.h>
 
-extern const char *xbt_log_priority_names[7];
+extern const char *xbt_log_priority_names[8];
 
-static double begin_of_time = -1;
+static double format_begin_of_time = -1;
 
 #define append1(fmt,fmt2,elm)                                         \
   do {                                                               \
@@ -147,7 +146,7 @@ static void xbt_log_layout_format_dynamic(xbt_log_layout_t l,
         append1("%f", "%.*f", gras_os_time());
         break;
       case 'r':                /* application age; LOG4J compliant */
-        append1("%f", "%.*f", gras_os_time() - begin_of_time);
+        append1("%f", "%.*f", gras_os_time() - format_begin_of_time);
         break;
 
       case 'm':                /* user-provided message; LOG4J compliant */
@@ -172,6 +171,7 @@ static void xbt_log_layout_format_dynamic(xbt_log_layout_t l,
   xbt_strbuff_free(buff);
 }
 
+#undef check_overflow
 #define check_overflow \
   if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
   xbt_log_layout_format_dynamic(l,ev,msg_fmt,app); \
@@ -185,8 +185,6 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l,
   char *p, *q;
   int precision = -1;
 
-  if (begin_of_time < 0)
-    begin_of_time = gras_os_time();
 
   p = ev->buffer;
   q = l->data;
@@ -444,13 +442,13 @@ static void xbt_log_layout_format_doit(xbt_log_layout_t l,
         if (precision == -1) {
           p +=
             snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%f",
-                     gras_os_time() - begin_of_time);
+                     gras_os_time() - format_begin_of_time);
           check_overflow;
         } else {
           p +=
             sprintf(p, "%.*f",
                     (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer),
-                              precision), gras_os_time() - begin_of_time);
+                              precision), gras_os_time() - format_begin_of_time);
           check_overflow;
           precision = -1;
         }
@@ -497,5 +495,9 @@ xbt_log_layout_t xbt_log_layout_format_new(char *arg)
   res->do_layout = xbt_log_layout_format_doit;
   res->free_ = xbt_log_layout_format_free;
   res->data = xbt_strdup((char *) arg);
+
+  if (format_begin_of_time < 0)
+    format_begin_of_time = gras_os_time();
+  
   return res;
 }