Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stupid me. I hadn't noticed the xbt_dict_get_or_null function...
[simgrid.git] / src / xbt / log.c
index 0b99261..9345c63 100644 (file)
@@ -7,15 +7,19 @@
 /* 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 <stdarg.h>
 #include <ctype.h>
+#include <stdio.h> /* snprintf */
+#include <stdlib.h> /* snprintf */
+#include "gras_config.h" /* to get a working stdarg.h */
 
 #include "xbt_modinter.h"
 
 #include "xbt/misc.h"
+#include "xbt/ex.h"
 #include "xbt/sysdep.h"
 #include "xbt/log.h"
-#include "xbt/error.h"
 #include "xbt/dynar.h"
 
 /** \addtogroup XBT_log
@@ -262,10 +266,9 @@ XBT_LOG_NEW_CATEGORY(surf,"All SURF categories");
 XBT_LOG_NEW_CATEGORY(msg,"All MSG categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log,xbt,"Loggings from the logging mechanism itself");
 
-void xbt_log_init(int *argc,char **argv, const char *defaultlog) {
+void xbt_log_init(int *argc,char **argv) {
   int i,j;
   char *opt;
-  int found=0;
 
   /* Set logs and init log submodule */
   for (i=1; i<*argc; i++) {
@@ -273,7 +276,6 @@ void xbt_log_init(int *argc,char **argv, const char *defaultlog) {
        !strncmp(argv[i],"--surf-log=",strlen("--surf-log=")) ||
        !strncmp(argv[i],"--msg-log=",strlen("--msg-log=")) ||
        !strncmp(argv[i],"--xbt-log=",strlen("--xbt-log="))) {
-      found = 1;
       opt=strchr(argv[i],'=');
       opt++;
       xbt_log_control_set(opt);
@@ -287,9 +289,6 @@ void xbt_log_init(int *argc,char **argv, const char *defaultlog) {
       i--; /* compensate effect of next loop incrementation */
     }
   }
-  if (!found && defaultlog) {
-     xbt_log_control_set(defaultlog);
-  }
 }
 
 void xbt_log_exit(void) {
@@ -321,7 +320,7 @@ static void _apply_control(xbt_log_category_t cat) {
 
       if (cat->threshold <= xbt_log_priority_debug) {
        s_xbt_log_event_t _log_ev = 
-         {cat,xbt_log_priority_debug,__FILE__,_XBT_GNUC_FUNCTION,__LINE__};
+         {cat,xbt_log_priority_debug,__FILE__,_XBT_FUNCTION,__LINE__};
        _xbt_log_event_log(&_log_ev,
                 "Apply settings for category '%s': set threshold to %s (=%d)",
                 cat->name, 
@@ -331,7 +330,7 @@ static void _apply_control(xbt_log_category_t cat) {
   }
   if (!found && cat->threshold <= xbt_log_priority_verbose) {
     s_xbt_log_event_t _log_ev = 
-      {cat,xbt_log_priority_verbose,__FILE__,_XBT_GNUC_FUNCTION,__LINE__};
+      {cat,xbt_log_priority_verbose,__FILE__,_XBT_FUNCTION,__LINE__};
     _xbt_log_event_log(&_log_ev,
                        "Category '%s': inherited threshold = %s (=%d)",
                        cat->name,
@@ -486,21 +485,16 @@ static void _xbt_log_parse_setting(const char*        control_string,
   DEBUG1("This is for cat '%s'", set->catname);
 }
 
-static xbt_error_t _xbt_log_cat_searchsub(xbt_log_category_t cat,char *name,
-                                           /*OUT*/xbt_log_category_t*whereto) {
-  xbt_error_t errcode;
+static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat,char *name) {
   xbt_log_category_t child;
   
   if (!strcmp(cat->name,name)) {
-    *whereto=cat;
-    return no_error;
+    return cat;
   }
   for(child=cat->firstChild ; child != NULL; child = child->nextSibling) {
-    errcode=_xbt_log_cat_searchsub(child,name,whereto);
-    if (errcode==no_error)
-      return no_error;
+    return _xbt_log_cat_searchsub(child,name);
   }
-  return mismatch_error;
+  THROW0(not_found_error,0,"No such category");
 }
 
 static void _cleanup_double_spaces(char *s) {
@@ -546,7 +540,7 @@ static void _cleanup_double_spaces(char *s) {
  * where [category] is one the category names and keyword is one of the
  * following:
  *
- *      thresh         value is an integer priority level. Sets the category's
+ *      thres                  value is an integer priority level. Sets the category's
  *                        threshold priority.
  *
  * \warning
@@ -554,7 +548,6 @@ static void _cleanup_double_spaces(char *s) {
  * logging command! Typically, this is done from main().
  */
 void xbt_log_control_set(const char* control_string) {
-  xbt_error_t errcode;
   xbt_log_setting_t set;
   char *cs;
   char *p;
@@ -574,6 +567,8 @@ void xbt_log_control_set(const char* control_string) {
 
   while (!done) {
     xbt_log_category_t cat;
+    int found;
+    xbt_ex_t e;
     
     p=strrchr(cs,' ');
     if (p) {
@@ -584,15 +579,24 @@ void xbt_log_control_set(const char* control_string) {
       done = 1;
     }
     _xbt_log_parse_setting(p,set);
-    
-    errcode = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname,&cat);
-    if (errcode == mismatch_error) {
+
+    TRY {
+      cat = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname);
+      found = 1;
+    } CATCH(e) {
+      if (e.category != not_found_error)
+       RETHROW;
+      xbt_ex_free(e);
+      found = 0;
+
       DEBUG0("Store for further application");
       DEBUG1("push %p to the settings",(void*)set);
       xbt_dynar_push(xbt_log_settings,&set);
       /* malloc in advance the next slot */
       set = xbt_new(s_xbt_log_setting_t,1);
-    } else {
+    } 
+
+    if (found) {
       DEBUG0("Apply directly");
       free(set->catname);
       xbt_log_threshold_set(cat,set->thresh);