Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the inclusion paths
[simgrid.git] / src / xbt / log.c
index e55a4c0..fb86a02 100644 (file)
@@ -8,16 +8,13 @@
 /* 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. */
 
-#include "Core/core_interface.h"
+
+#include "gros_interface.h"
 #include "gras_private.h"
 #include <stdarg.h>
 #include <assert.h>
 #include <ctype.h>
 
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
 typedef struct {
   char *catname;
   gras_log_priority_t thresh;
@@ -28,12 +25,13 @@ static void _free_setting(void *s) {
   gras_log_setting_t *set=(gras_log_setting_t*)s;
   if (set) {
     free(set->catname);
-    free(set);
+//    free(set); FIXME: uncommenting this leads to segfault when more than one chunk is passed as gras-log
   }
 }
 
 const char *gras_log_priority_names[8] = {
   "NONE",
+  "TRACE",
   "DEBUG",
   "VERBOSE",
   "INFO",
@@ -48,7 +46,8 @@ gras_log_category_t _GRAS_LOGV(GRAS_LOG_ROOT_CAT) = {
   NULL, 0
 };
 GRAS_LOG_NEW_SUBCATEGORY(GRAS,GRAS_LOG_ROOT_CAT);
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log,GRAS);
+GRAS_LOG_NEW_SUBCATEGORY(tbx,GRAS);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log,tbx);
 
 
 static void _apply_control(gras_log_category_t* cat) {
@@ -74,30 +73,32 @@ static void _apply_control(gras_log_category_t* cat) {
 
       if (cat->threshold <= gras_log_priority_verbose) {
        gras_log_event_t _log_ev = 
-         {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__,
-          "Apply settings for category '%s': set threshold to %s (=%d)",};
-       _gras_log_event_log(&_log_ev, cat->name,
-                           gras_log_priority_names[cat->threshold], cat->threshold);
+         {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__};
+       _gras_log_event_log(&_log_ev,
+                "Apply settings for category '%s': set threshold to %s (=%d)",
+                cat->name, 
+                gras_log_priority_names[cat->threshold], cat->threshold);
       }
     }
   }
   if (!found && cat->threshold <= gras_log_priority_verbose) {
     gras_log_event_t _log_ev = 
-      {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__,
-       "Category '%s': inherited threshold = %s (=%d)",};
-    _gras_log_event_log(&_log_ev, cat->name,
+      {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__};
+    _gras_log_event_log(&_log_ev,
+                       "Category '%s': inherited threshold = %s (=%d)",
+                       cat->name,
                        gras_log_priority_names[cat->threshold], cat->threshold);
   }
 
 }
 
-void _gras_log_event_log( gras_log_event_t* ev, ...) {
+void _gras_log_event_log( gras_log_event_t* ev, const char *fmt, ...) {
   gras_log_category_t* cat = ev->cat;
-  va_start(ev->ap, ev);
+  va_start(ev->ap, fmt);
   while(1) {
     gras_log_appender_t* appender = cat->appender;
     if (appender != NULL) {
-      appender->do_append(appender, ev);
+      appender->do_append(appender, ev, fmt);
     }
     if (!cat->willLogToParent)
       break;
@@ -201,7 +202,7 @@ static gras_error_t _gras_log_parse_setting(const char* control_string,
   gras_assert1(*dot == '.' && *eq == '=',
               "Invalid control string '%s'",control_string);
 
-  if (!strncmp(dot + 1, "thresh", MIN(eq - dot - 1,strlen("thresh")))) {
+  if (!strncmp(dot + 1, "thresh", min(eq - dot - 1,strlen("thresh")))) {
     int i;
     char *neweq=strdup(eq+1);
     char *p=neweq-1;
@@ -213,13 +214,13 @@ static gras_error_t _gras_log_parse_setting(const char* control_string,
     }
     
     DEBUG1("New priority name = %s",neweq);
-    for (i=0; i<6; i++) {
+    for (i=0; i<gras_log_priority_infinite-1; i++) {
       if (!strncmp(gras_log_priority_names[i],neweq,p-eq)) {
        DEBUG1("This is priority %d",i);
        break;
       }
     }
-    if (i<6) {
+    if (i<gras_log_priority_infinite-1) {
       set->thresh=i;
     } else {
       gras_assert1(FALSE,"Unknown priority name: %s",eq+1);
@@ -227,7 +228,7 @@ static gras_error_t _gras_log_parse_setting(const char* control_string,
     free(neweq);
   } else {
     char buff[512];
-    snprintf(buff,MIN(512,eq - dot - 1),"%s",dot+1);
+    snprintf(buff,min(512,eq - dot - 1),"%s",dot+1);
     gras_assert1(FALSE,"Unknown setting of the log category: %s",buff);
   }
   if (!(set->catname=malloc(dot - name+1)))