Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First attempt to display log categoy hierarchy.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 28 Mar 2012 13:41:54 +0000 (15:41 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 28 Mar 2012 14:07:38 +0000 (16:07 +0200)
include/xbt/log.h
src/surf/surf_config.c
src/xbt/log.c

index 26fdf6f..3b77db3 100644 (file)
@@ -361,6 +361,13 @@ extern xbt_log_layout_t xbt_log_default_layout;
  */
 XBT_PUBLIC(void) xbt_log_help(void);
 
+/**
+ * \ingroup XBT_log
+ *
+ * Prints the log category hierarchy.
+ */
+XBT_PUBLIC(void) xbt_log_help_categories(void);
+
 /**
  * \ingroup XBT_log 
  * \param catName name of the category
index 52e6887..816709c 100644 (file)
@@ -44,7 +44,7 @@ static void surf_config_cmd_line(int *argc, char **argv)
 "You can also use --help-tracing to see the details of all tracing options known by this simulator.\n"
 #endif
 "\n"
-"You can also use --help-logs to see the details of logging output.\n"
+"You can also use --help-logs and --help-log-categories to see the details of logging output.\n"
 "\n"
         );
       shall_exit = 1;
@@ -66,6 +66,9 @@ static void surf_config_cmd_line(int *argc, char **argv)
     } else if (!strcmp(argv[i], "--help-logs")) {
       xbt_log_help();
       shall_exit = 1;
+    } else if (!strcmp(argv[i], "--help-log-categories")) {
+      xbt_log_help_categories();
+      shall_exit = 1;
 #ifdef HAVE_TRACING
     } else if (!strcmp(argv[i], "--help-tracing")) {
       TRACE_help (1);
index f6c02c4..2b4f6e2 100644 (file)
@@ -1153,3 +1153,56 @@ void xbt_log_help(void)
 "\n"
     );
 }
+
+static int xbt_log_cat_cmp(const void *pa, const void *pb)
+{
+  xbt_log_category_t a = *(xbt_log_category_t *)pa;
+  xbt_log_category_t b = *(xbt_log_category_t *)pb;
+  return strcmp(a->name, b->name);
+}
+
+static void xbt_log_help_categories_rec(xbt_log_category_t category,
+                                        const char *prefix)
+{
+  char *this_prefix;
+  char *child_prefix;
+  xbt_dynar_t dynar;
+  unsigned i;
+  xbt_log_category_t cat;
+
+  if (!category)
+    return;
+
+  if (category->parent) {
+    this_prefix = bprintf("%s \\_ ", prefix);
+    child_prefix = bprintf("%s |  ", prefix);
+  } else {
+    this_prefix = bprintf("%s", prefix);
+    child_prefix = bprintf("%s", prefix);
+  }
+
+  dynar = xbt_dynar_new(sizeof(xbt_log_category_t), NULL);
+  for (cat = category ; cat != NULL; cat = cat->nextSibling)
+    xbt_dynar_push_as(dynar, xbt_log_category_t, cat);
+
+  xbt_dynar_sort(dynar, xbt_log_cat_cmp);
+
+  for (i = 0; i < xbt_dynar_length(dynar); i++) {
+    if (i == xbt_dynar_length(dynar) - 1 && category->parent)
+      *strrchr(child_prefix, '|') = ' ';
+    cat = xbt_dynar_get_as(dynar, i, xbt_log_category_t);
+    printf("%s%s\n", this_prefix, cat->name);
+    xbt_log_help_categories_rec(cat->firstChild, child_prefix);
+  }
+
+  xbt_dynar_free(&dynar);
+  xbt_free(this_prefix);
+  xbt_free(child_prefix);
+}
+
+void xbt_log_help_categories(void)
+{
+  printf("Current log category hierarchy:\n");
+  xbt_log_help_categories_rec(&_XBT_LOGV(XBT_LOG_ROOT_CAT), "   ");
+  printf("\n");
+}