Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use verbose instead of debug-
[simgrid.git] / src / xbt / log.c
index 44ff420..b4e3010 100644 (file)
@@ -24,7 +24,7 @@
 #include "xbt/dynar.h"
 
 XBT_PUBLIC_DATA(int) (*xbt_pid) ();
-int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */
+int xbt_log_no_loc = 0;         /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */
 
 /** \addtogroup XBT_log
  *
@@ -269,17 +269,17 @@ int main() {
        xbt_log_control_set("SA.thresh:3");
 
        / * This request is enabled, because WARNING >= INFO. * /
-       CWARN2(VSS, "Low fuel level.");
+       CWARN0(VSS, "Low fuel level.");
 
        / * This request is disabled, because DEBUG < INFO. * /
-       CDEBUG2(VSS, "Starting search for nearest gas station.");
+       CDEBUG0(VSS, "Starting search for nearest gas station.");
 
        / * The default category SA inherits its priority from VSS. Thus,
           the following request is enabled because INFO >= INFO.  * /
-       INFO1("Located nearest gas station.");
+       INFO0("Located nearest gas station.");
 
        / * This request is disabled, because DEBUG < INFO. * /
-       DEBUG1("Exiting gas station search");
+       DEBUG0("Exiting gas station search");
 }
 \endverbatim
 
@@ -364,18 +364,25 @@ Here are the existing format directives:
 
 
 If you want to mimic the simple layout with the format one, you would use this
-format: '[%%h:%%i:(%%I) %%r] %%l: [%%c/%%p] %%m%%n'. This is not completely correct
+format: '[%%h:%%i:(%%i) %%r] %%l: [%%c/%%p] %%m%%n'. This is not completely correct
 because the simple layout do not display the message location for messages at
-priority INFO (thus, the fmt is '[%%h:%%i:(%%I) %%r] %%l: [%%c/%%p] %%m%%n' in this
+priority INFO (thus, the fmt is '[%%h:%%i:(%%i) %%r] [%%c/%%p] %%m%%n' in this
 case). Moreover, if there is no process name (ie, messages coming from the
 library itself, or test programs doing strange things) do not display the
 process identity (thus, fmt is '[%%r] %%l: [%%c/%%p] %%m%%n' in that case, and '[%%r]
 [%%c/%%p] %%m%%n' if they are at priority INFO).
 
-For now, there is only one format modifier: the precision field. You
-can for example specify %.4r to get the application age with 4
-numbers after the radix. Another limitation is that you cannot set
-specific layouts to the several priorities.
+For now, there is only two format modifiers: the precision and the
+width fields. You can for example specify %.4r to get the application
+age with 4 numbers after the radix, or %15p to get the process name
+on 15 columns. Finally, you can specify %10.6r to get the time on at
+most 10 columns, with 6 numbers after the radix. 
+
+Note that when specifying the width, it is filled with spaces. That
+is to say that for example %5r in your format is converted to "% 5f"
+for printf (note the extra space); there is no way to fill the empty
+columns with 0 (ie, pass "%05f" to printf). Another limitation is
+that you cannot set specific layouts to the several priorities.
 
 \subsection log_use_conf_app 3.1.4 Category appender
 
@@ -463,7 +470,7 @@ This is on our TODO list for quite a while now, but your help would be
 welcome here, too.
 
 
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              *//*' */
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              *//*' */
 
 
 xbt_log_appender_t xbt_log_default_appender = NULL;     /* set in log_init */
@@ -506,10 +513,10 @@ const char *xbt_log_priority_names[8] = {
 
 s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = {
   NULL /*parent */ , NULL /* firstChild */ , NULL /* nextSibling */ ,
-    "root", xbt_log_priority_uninitialized /* threshold */ ,
-    0 /* isThreshInherited */ ,
-    NULL /* appender */ , NULL /* layout */ ,
-    0                           /* additivity */
+      "root", xbt_log_priority_uninitialized /* threshold */ ,
+      0 /* isThreshInherited */ ,
+      NULL /* appender */ , NULL /* layout */ ,
+      0                         /* additivity */
 };
 
 XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)");
@@ -524,7 +531,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt,
 
 /* create the default appender and install it in the root category,
    which were already created (damnit. Too slow little beetle) */
-void xbt_log_preinit(void) {
+void xbt_log_preinit(void)
+{
   xbt_log_default_appender = xbt_log_appender_file_new(NULL);
   xbt_log_default_layout = xbt_log_layout_simple_new(NULL);
   _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender;
@@ -535,7 +543,8 @@ void xbt_log_preinit(void) {
  *
  * xbt_log_control_set() is called on each string we got from cmd line
  */
-void xbt_log_init(int *argc, char **argv) {
+void xbt_log_init(int *argc, char **argv)
+{
   int i, j;
   char *opt;
 
@@ -552,8 +561,8 @@ void xbt_log_init(int *argc, char **argv) {
 
       if (strncmp(argv[i], "--log=", strlen("--log=")))
         WARN2
-          ("Option %.*s is deprecated and will disapear in the future. Use --log instead.",
-           (int) (strchr(argv[i], '=') - argv[i]), argv[i]);
+            ("Option %.*s is deprecated and will disapear in the future. Use --log instead.",
+             (int) (strchr(argv[i], '=') - argv[i]), argv[i]);
 
       opt = strchr(argv[i], '=');
       opt++;
@@ -672,7 +681,6 @@ static void _xbt_log_cat_apply_set(xbt_log_category_t category,
     DEBUG2("Set %p as appender of category '%s'",
            setting->appender, category->name);
   }
-
 #undef _xbt_log_cat_init
 }
 
@@ -708,7 +716,8 @@ int _xbt_log_cat_init(xbt_log_category_t category,
     DEBUG3("Set %s (%s) as father of %s ",
            category->parent->name,
            (category->parent->threshold == xbt_log_priority_uninitialized ?
-            "uninited" : xbt_log_priority_names[category->parent->threshold]),
+            "uninited" : xbt_log_priority_names[category->
+                                                parent->threshold]),
            category->name);
     xbt_log_parent_set(category, category->parent);
 
@@ -797,7 +806,8 @@ void xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent)
 
   if (parent->threshold == xbt_log_priority_uninitialized) {
 
-    _xbt_log_cat_init(parent, xbt_log_priority_uninitialized /* ignored */ );
+    _xbt_log_cat_init(parent,
+                      xbt_log_priority_uninitialized /* ignored */ );
   }
 
   cat->threshold = parent->threshold;
@@ -899,7 +909,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string)
         *p -= 'a' - 'A';
       }
     }
-    if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES") || !strcmp(neweq, "1")) {
+    if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES")
+        || !strcmp(neweq, "1")) {
       set->additivity = 1;
     } else {
       set->additivity = 0;
@@ -921,7 +932,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string)
   } else {
     char buff[512];
     snprintf(buff, min(512, eq - dot), "%s", dot + 1);
-    THROW1(arg_error, 0, "Unknown setting of the log category: '%s'", buff);
+    THROW1(arg_error, 0, "Unknown setting of the log category: '%s'",
+           buff);
   }
   set->catname = (char *) xbt_malloc(dot - name + 1);
 
@@ -990,8 +1002,8 @@ void xbt_log_control_set(const char *control_string)
   DEBUG1("Parse log settings '%s'", control_string);
 
   /* Special handling of no_loc request, which asks for any file localization to be omitted (for tesh runs) */
-  if (!strcmp(control_string,"no_loc")) {
-    xbt_log_no_loc=1;
+  if (!strcmp(control_string, "no_loc")) {
+    xbt_log_no_loc = 1;
     return;
   }
   /* some initialization if this is the first time that this get called */
@@ -1013,7 +1025,8 @@ void xbt_log_control_set(const char *control_string)
     xbt_log_category_t cat = NULL;
 
     set = _xbt_log_parse_setting(str);
-    cat = _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname);
+    cat =
+        _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname);
 
     if (cat) {
       DEBUG0("Apply directly");
@@ -1042,17 +1055,16 @@ void xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app)
 void xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay)
 {
   if (!cat->appender) {
-    VERB1("No appender to category %s. Setting the file appender as default",
-          cat->name);
+    VERB1
+        ("No appender to category %s. Setting the file appender as default",
+         cat->name);
     xbt_log_appender_set(cat, xbt_log_appender_file_new(NULL));
   }
-  if (cat->layout && cat != &_XBT_LOGV(root)) {
-    /* better leak the default layout than check every categories to
-       change it */
+  if (cat->layout) {
     if (cat->layout->free_) {
       cat->layout->free_(cat->layout);
-      free(cat->layout);
     }
+    free(cat->layout);
   }
   cat->layout = lay;
   xbt_log_additivity_set(cat, 0);