Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate all the --*-log option. With the module multiplication, it became a mess...
[simgrid.git] / src / xbt / log.c
1 /* $Id$ */
2
3 /* log - a generic logging facility in the spirit of log4j                  */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10
11 #include <stdarg.h>
12 #include <ctype.h>
13 #include <stdio.h> /* snprintf */
14 #include <stdlib.h> /* snprintf */
15
16 #include "portable.h" /* to get a working stdarg.h */
17
18 #include "xbt_modinter.h"
19
20 #include "xbt/misc.h"
21 #include "xbt/ex.h"
22 #include "xbt/sysdep.h"
23 #include <xbt/log.h>
24 #include "xbt/dynar.h"
25
26 /** \addtogroup XBT_log
27  *
28  *  This section describes the API to the log functions used 
29  *  everywhere in this project.
30
31 \section XBT_log_toc Table of contents
32  
33  - \ref log_overview
34    - \ref log_cat
35    - \ref log_pri
36    - \ref log_app
37    - \ref log_hist
38  - \ref log_API
39    - \ref log_API_cat
40    - \ref log_API_pri
41    - \ref log_API_subcat
42    - \ref log_API_easy
43    - \ref log_API_example
44  - \ref log_user
45    - \ref log_use_conf
46    - \ref log_use_misc
47  - \ref log_internals
48    - \ref log_in_perf
49    - \ref log_in_app
50  - \ref XBT_log_cats
51      
52 \section log_overview 1. Introduction
53
54 This module is in charge of handling the log messages of every SimGrid
55 program. The main design goal are:
56
57   - <b>configurability</b>: the user can choose <i>at runtime</i> what messages to show and 
58     what to hide, as well as how messages get displayed.
59   - <b>ease of use</b>: both to the programmer (using preprocessor macros black magic)
60     and to the user (with command line options)
61   - <b>performances</b>: logging shouldn't slow down the program when turned off, for example
62   - deal with <b>distributed settings</b>: SimGrid programs are [often] distributed ones, 
63     and the logging mecanism allows to syndicate each and every log source into the same place.
64     At least, its design would allow to, once we write the last missing pieces
65      
66 There is three main concepts in SimGrid's logging mecanism: <i>category</i>,
67 <i>priority</i> and <i>appender</i>. These three concepts work together to
68 enable developers to log messages according to message type and priority, and
69 to control at runtime how these messages are formatted and where they are
70 reported. 
71
72 \subsection log_cat 1.1 Category hierarchy
73
74 The first and foremost advantage of any logging API over plain printf()
75 resides in its ability to disable certain log statements while allowing
76 others to print unhindered. This capability assumes that the logging space,
77 that is, the space of all possible logging statements, is categorized
78 according to some developer-chosen criteria. 
79           
80 This observation led to choosing category as the central concept of the
81 system. In a certain sense, they can be considered as logging topics or
82 channels.
83
84 \subsection log_pri 1.2 Logging priorities
85
86 The user can naturally declare interest into this or that logging category, but
87 he also can specify the desired level of details for each of them. This is
88 controled by the <i>priority</i> concept (which should maybe be renamed to
89 <i>severity</i>). 
90
91 Empirically, the user can specify that he wants to see every debuging message
92 of GRAS while only being interested into the messages at level "error" or
93 higher about the XBT internals.
94
95 \subsection log_app 1.3 Message appenders
96
97 The message appenders are the elements in charge of actually displaying the
98 message to the user. For now, there is only one appender: the one able to print
99 stuff on stderr. But everything is in place internally to write new ones, such
100 as the one able to send the strings to a central server in charge of
101 syndicating the logs of every distributed daemons on a well known location.
102
103 It should also be possible to pass configuration informations to the appenders,
104 specifying for example that the message location (file and line number) is only
105 relevant to debugging information, not to critical error messages.
106
107 One day, for sure ;)
108
109 \subsection log_hist 1.4 History of this module
110
111 Historically, this module is an adaptation of the log4c project, which is dead
112 upstream, and which I was given the permission to fork under the LGPL licence
113 by the log4c's authors. The log4c project itself was loosely based on the
114 Apache project's Log4J, which also inspired Log4CC, Log4py and so on. Our work
115 differs somehow from these projects anyway, because the C programming language
116 is not object oriented.
117
118 \section log_API 2. Programmer interface
119
120 \subsection log_API_cat 2.1 Constructing the category hierarchy
121
122 Every category is declared by providing a name and an optional
123 parent. If no parent is explicitly named, the root category, LOG_ROOT_CAT is
124 the category's parent. 
125       
126 A category is created by a macro call at the top level of a file.  A
127 category can be created with any one of the following macros:
128
129  - \ref XBT_LOG_NEW_CATEGORY(MyCat,desc); Create a new root
130  - \ref XBT_LOG_NEW_SUBCATEGORY(MyCat, ParentCat,desc);
131     Create a new category being child of the category ParentCat
132  - \ref XBT_LOG_NEW_DEFAULT_CATEGORY(MyCat,desc);
133     Like XBT_LOG_NEW_CATEGORY, but the new category is the default one
134       in this file
135  -  \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY(MyCat, ParentCat,desc);
136     Like XBT_LOG_NEW_SUBCATEGORY, but the new category is the default one
137       in this file
138             
139 The parent cat can be defined in the same file or in another file (in
140 which case you want to use the \ref XBT_LOG_EXTERNAL_CATEGORY macro to make
141 it visible in the current file), but each category may have only one
142 definition.
143       
144 Typically, there will be a Category for each module and sub-module, so you
145 can independently control logging for each module.
146
147 For a list of all existing categories, please refer to the \ref XBT_log_cats
148 section. This file is generated automatically from the SimGrid source code, so
149 it should be complete and accurate.
150
151 \section log_API_pri 2.2 Declaring message priority
152
153 A category may be assigned a threshold priorty. The set of priorites are
154 defined by the \ref e_xbt_log_priority_t enum. All logging request under
155 this priority will be discarded.
156           
157 If a given category is not assigned a threshold priority, then it inherits
158 one from its closest ancestor with an assigned threshold. To ensure that all
159 categories can eventually inherit a threshold, the root category always has
160 an assigned threshold priority.
161
162 Logging requests are made by invoking a logging macro on a category.  All of
163 the macros have a printf-style format string followed by arguments. If you
164 compile with the -Wall option, gcc will warn you for unmatched arguments, ie
165 when you pass a pointer to a string where an integer was specified by the
166 format. This is usualy a good idea.
167
168 Because some C compilers do not support vararg macros, there is a version of
169 the macro for any number of arguments from 0 to 6. The macro name ends with
170 the total number of arguments.
171         
172 Here is an example of the most basic type of macro. This is a logging
173 request with priority <i>warning</i>.
174
175 <code>CLOG5(MyCat, gras_log_priority_warning, "Values are: %d and '%s'", 5,
176 "oops");</code>
177
178 A logging request is said to be enabled if its priority is higher than or
179 equal to the threshold priority of its category. Otherwise, the request is
180 said to be disabled. A category without an assigned priority will inherit
181 one from the hierarchy. 
182       
183 It is possible to use any non-negative integer as a priority. If, as in the
184 example, one of the standard priorites is used, then there is a convenience
185 macro that is typically used instead. For example, the above example is
186 equivalent to the shorter:
187
188 <code>CWARN4(MyCat, "Values are: %d and '%s'", 5, "oops");</code>
189
190 \section log_API_subcat 2.3 Using a default category (the easy interface)
191   
192 If \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY(MyCat, Parent) or
193 \ref XBT_LOG_NEW_DEFAULT_CATEGORY(MyCat) is used to create the
194 category, then the even shorter form can be used:
195
196 <code>WARN3("Values are: %d and '%s'", 5, "oops");</code>
197
198 Only one default category can be created per file, though multiple
199 non-defaults can be created and used.
200
201 \section log_API_easy 2.4 Putting all together: the easy interface
202
203 First of all, each module should register its own category into the categories
204 tree using \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY.
205
206 Then, logging should be done with the DEBUG<n>, VERB<n>, INFO<n>, WARN<n>,
207 ERROR<n> or CRITICAL<n> macro families (such as #DEBUG10, #VERB6,
208 #INFO8, #WARN6, #ERROR6 and #CRITICAL6). For each group, there is at
209 least 6 different macros (like DEBUG0, DEBUG1, DEBUG2, DEBUG3, DEBUG4 and
210 DEBUG5), only differing in the number of arguments passed along the format.
211 This is because we want SimGrid itself to keep compilable on ancient
212 compiler not supporting variable number of arguments to macros. But we
213 should provide a macro simpler to use for the users not interested in SP3
214 machines (FIXME).
215   
216 Under GCC, these macro check there arguments the same way than printf does. So,
217 if you compile with -Wall, the folliwing code will issue a warning:
218 <code>DEBUG2("Found %s (id %f)", some_string, a_double)</code>
219
220 If you want to specify the category to log onto (for example because you
221 have more than one category per file, add a C before the name of the log
222 producing macro (ie, use #CDEBUG10, #CVERB6, #CINFO8, #CWARN6, #CERROR6 and
223 #CCRITICAL6 and friends), and pass the category name as first argument.
224   
225 The TRACE priority is not used the same way than the other. You should use
226 the #XBT_IN, XBT_IN<n> (up to #XBT_IN5), #XBT_OUT and #XBT_HERE macros
227 instead.
228
229 \section log_API_example 2.5 Example of use
230
231 Here is a more complete example:
232
233 \verbatim
234 #include "xbt/log.h"
235
236 / * create a category and a default subcategory * /
237 XBT_LOG_NEW_CATEGORY(VSS);
238 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(SA, VSS);
239
240 int main() {
241        / * Now set the parent's priority.  (the string would typcially be a runtime option) * /
242        xbt_log_control_set("SA.thresh:3");
243
244        / * This request is enabled, because WARNING &gt;= INFO. * /
245        CWARN2(VSS, "Low fuel level.");
246
247        / * This request is disabled, because DEBUG &lt; INFO. * /
248        CDEBUG2(VSS, "Starting search for nearest gas station.");
249
250        / * The default category SA inherits its priority from VSS. Thus,
251           the following request is enabled because INFO &gt;= INFO.  * /
252        INFO1("Located nearest gas station.");
253
254        / * This request is disabled, because DEBUG &lt; INFO. * /
255        DEBUG1("Exiting gas station search"); 
256 }
257 \endverbatim
258
259
260 \section log_user 3. User interface
261
262 \section log_use_conf 3.1 Configuration
263 Configuration is typically done during program initialization by invoking
264 the xbt_log_control_set() method. The control string passed to it typically
265 comes from the command line. Look at the documentation for that function for
266 the format of the control string.
267
268 Any SimGrid program can furthermore be configured at run time by passing a
269 --xbt-log argument on the command line (--gras-log, --msg-log and --surf-log
270 are synonyms provided by aestheticism). You can provide several of those
271 arguments to change the setting of several categories, they will be applied
272 from left to right. So, 
273 \verbatim --xbt-log="root.thres:debug root.thres:critical"\endverbatim 
274 should disable any logging.
275
276 Note that the quotes on above line are mandatory because there is a space in
277 the argument, so we are protecting ourselves from the shell, not from SimGrid.
278 We could also reach the same effect with this:
279 \verbatim --xbt-log=root.thres:debug --xbt-log=root.thres:critical\endverbatim 
280
281 \section log_use_misc 3.2 Misc and Caveats
282
283   - Do not use any of the macros that start with '_'.
284   - Log4J has a 'rolling file appender' which you can select with a run-time
285     option and specify the max file size. This would be a nice default for
286     non-kernel applications.
287   - Careful, category names are global variables.
288
289 \section log_internals 4. Internal considerations
290
291 This module is a mess of macro black magic, and when it goes wrong, SimGrid
292 studently loose its ability to explain its problems. When messing around this
293 module, I often find useful to define XBT_LOG_MAYDAY (which turns it back to
294 good old printf) for the time of finding what's going wrong.
295
296 \section log_in_perf 4.1 Performance
297
298 Except for the first invocation of a given category, a disabled logging request
299 requires an a single comparison of a static variable to a constant.
300
301 There is also compile time constant, \ref XBT_LOG_STATIC_THRESHOLD, which
302 causes all logging requests with a lower priority to be optimized to 0 cost
303 by the compiler. By setting it to gras_log_priority_infinite, all logging
304 requests are statically disabled and cost nothing. Released executables
305 might be compiled with
306 \verbatim-DXBT_LOG_STATIC_THRESHOLD=gras_log_priority_infinite\endverbatim
307
308 Compiling with the \verbatim-DNLOG\endverbatim option disables all logging 
309 requests at compilation time while the \verbatim-DNDEBUG\endverbatim disables 
310 the requests of priority below INFO.
311
312 \todo Logging performance *may* be improved further by improving the message
313 propagation from appender to appender in the category tree.
314
315 \section log_in_app 4.2 Appenders
316
317 Each category has an optional appender. An appender is a pointer to a
318 structure which starts with a pointer to a doAppend() function. DoAppend()
319 prints a message to a log.
320
321 When a category is passed a message by one of the logging macros, the
322 category performs the following actions:
323
324   - if the category has an appender, the message is passed to the
325     appender's doAppend() function,
326   - if additivity is true for the category (which is the case by
327     default, and can be controlled by xbt_log_additivity_set()), the 
328     message is passed to the category's parent. 
329     
330 By default, only the root category have an appender, and any other category has
331 its additivity set to true. This causes all messages to be logged by the root
332 category's appender.
333
334 The default appender function currently prints to stderr, and no other one
335 exist, even if more would be needed, like the one able to send the logs to a
336 remote dedicated server, or other ones offering different output formats.
337 This is on our TODO list for quite a while now, but your help would be
338 welcome here, too.
339
340
341 */
342
343 \f
344 xbt_log_appender_t xbt_log_default_appender = NULL; /* set in log_init */
345 xbt_log_layout_t xbt_log_default_layout = NULL; /* set in log_init */
346
347 typedef struct {
348   char *catname;
349   e_xbt_log_priority_t thresh;
350 } s_xbt_log_setting_t,*xbt_log_setting_t;
351
352 static xbt_dynar_t xbt_log_settings=NULL;
353
354 static void _free_setting(void *s) {
355   xbt_log_setting_t set=*(xbt_log_setting_t*)s;
356   if (set) {
357     free(set->catname);
358     free(set);
359   }
360 }
361
362 const char *xbt_log_priority_names[8] = {
363   "NONE",
364   "TRACE",
365   "DEBUG",
366   "VERBOSE",
367   "INFO",
368   "WARNING",
369   "ERROR",
370   "CRITICAL"
371 };
372
373 XBT_PUBLIC_DATA(s_xbt_log_category_t)  _XBT_LOGV(XBT_LOG_ROOT_CAT) = {
374   0, 0, 0,
375   "root", xbt_log_priority_uninitialized, 0,
376   NULL, 0
377 };
378
379 XBT_LOG_NEW_CATEGORY(xbt,"All XBT categories (simgrid toolbox)");
380 XBT_LOG_NEW_CATEGORY(surf,"All SURF categories");
381 XBT_LOG_NEW_CATEGORY(msg,"All MSG categories");
382 XBT_LOG_NEW_CATEGORY(simix,"All SIMIX categories");
383 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log,xbt,"Loggings from the logging mechanism itself");
384
385 /** @brief Get all logging settings from the command line
386  * 
387  * xbt_log_control_set() is called on each string we got from cmd line
388  */
389 void xbt_log_init(int *argc,char **argv) {
390         int i,j;
391         char *opt;
392         
393         /* create the default appender and install it in the root category,
394            which were already created (damnit. Too slow little beetle)*/
395         xbt_log_default_appender = xbt_log_appender_file_new(NULL);
396         xbt_log_default_layout = xbt_log_layout_simple_new(NULL);
397         _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender;
398         _XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout;
399
400         /* Set logs and init log submodule */
401         for (i=1; i<*argc; i++){
402                 if (!strncmp(argv[i],"--log=",strlen("--log=")) ||
403                     !strncmp(argv[i],"--gras-log=",strlen("--gras-log=")) ||
404                     !strncmp(argv[i],"--surf-log=",strlen("--surf-log=")) ||
405                     !strncmp(argv[i],"--msg-log=",strlen("--msg-log=")) ||
406                     !strncmp(argv[i],"--simix-log=",strlen("--simix-log=")) ||
407                     !strncmp(argv[i],"--xbt-log=",strlen("--xbt-log="))){
408                         
409                   if (strncmp(argv[i],"--log=",strlen("--log=")))
410                       WARN2("Option %.*s is deprecated and will disapear in the future. Use --log instead.",
411                             strchr(argv[i],'=')-argv[i],argv[i]);
412
413                   opt=strchr(argv[i],'=');
414                   opt++;
415                   xbt_log_control_set(opt);
416                   DEBUG1("Did apply '%s' as log setting",opt);
417                   /*remove this from argv*/
418                   
419                   for (j=i+1; j<*argc; j++){
420                     argv[j-1] = argv[j];
421                   } 
422                   
423                   argv[j-1] = NULL;
424                   (*argc)--;
425                   i--; /* compensate effect of next loop incrementation */
426                 }
427         }
428 }
429
430 static void log_cat_exit(xbt_log_category_t cat) {
431   xbt_log_category_t child;
432
433   if (cat->appender) {
434     if (cat->appender->free_)
435       cat->appender->free_(cat->appender);
436     free(cat->appender);
437   }
438   if (cat->layout) {
439     if (cat->layout->free_)
440       cat->layout->free_(cat->layout);
441     free(cat->layout);
442   }    
443
444   for(child=cat->firstChild ; child != NULL; child = child->nextSibling) 
445     log_cat_exit(child);
446 }
447
448 void xbt_log_exit(void) {
449   VERB0("Exiting log");
450   xbt_dynar_free(&xbt_log_settings);
451   log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT));
452   VERB0("Exited log");
453 }
454
455 void _xbt_log_event_log( xbt_log_event_t ev, const char *fmt, ...) {
456   
457   xbt_log_category_t cat = ev->cat;
458   
459   va_start(ev->ap, fmt);
460   while(1) {
461     xbt_log_appender_t appender = cat->appender;
462     if (appender != NULL) {
463       xbt_assert1(cat->layout,"No valid layout for the appender of category %s",cat->name);
464       char *str= cat->layout->do_layout(cat->layout, ev, fmt);    
465       appender->do_append(appender, str);
466     }
467     if (!cat->additivity)
468       break;
469
470     cat = cat->parent;
471   } 
472   va_end(ev->ap);
473 }
474
475 /*
476  * This gets called the first time a category is referenced and performs the
477  * initialization. 
478  * Also resets threshold to inherited!
479  */
480 int _xbt_log_cat_init(xbt_log_category_t category,
481                       e_xbt_log_priority_t priority) {
482   int cursor;
483   xbt_log_setting_t setting=NULL;
484   int found = 0;
485   s_xbt_log_event_t _log_ev;
486         
487   if(category == &_XBT_LOGV(XBT_LOG_ROOT_CAT)){
488     category->threshold = xbt_log_priority_info;/* xbt_log_priority_debug*/;
489     category->appender = xbt_log_default_appender;
490     category->layout = xbt_log_default_layout;
491   } else {
492
493     if (!category->parent)
494       category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT);
495     
496     xbt_log_parent_set(category, category->parent);
497   }
498
499   /* Apply the control */  
500   if (!xbt_log_settings)
501     return priority >= category->threshold;
502   
503   xbt_assert0(category,"NULL category");
504   xbt_assert(category->name);
505   
506   xbt_dynar_foreach(xbt_log_settings,cursor,setting) {
507     xbt_assert0(setting,"Damnit, NULL cat in the list");
508     xbt_assert1(setting->catname,"NULL setting(=%p)->catname",(void*)setting);
509     
510     if (!strcmp(setting->catname,category->name)) {
511       
512       found = 1;
513       
514       xbt_log_threshold_set(category, setting->thresh);
515       xbt_dynar_cursor_rm(xbt_log_settings,&cursor);
516
517       if (category->threshold <= xbt_log_priority_debug) {
518         _log_ev.cat = category;
519         _log_ev.priority = xbt_log_priority_debug;
520         _log_ev.fileName = __FILE__ ;
521         _log_ev.functionName = _XBT_FUNCTION ;
522         _log_ev.lineNum = __LINE__ ;
523         
524         _xbt_log_event_log(&_log_ev,
525                            "Apply settings for category '%s': set threshold to %s (=%d)",
526                            category->name,
527                            xbt_log_priority_names[category->threshold], category->threshold);
528       }
529     }
530   }
531   
532   if (!found && category->threshold <= xbt_log_priority_verbose) {
533     
534     _log_ev.cat = category;
535     _log_ev.priority = xbt_log_priority_verbose;
536     _log_ev.fileName = __FILE__ ;
537     _log_ev.functionName = _XBT_FUNCTION ;
538     _log_ev.lineNum = __LINE__ ;
539     
540     _xbt_log_event_log(&_log_ev,
541                        "Category '%s': inherited threshold = %s (=%d)",
542                        category->name,
543                        xbt_log_priority_names[category->threshold], category->threshold);
544   }
545     
546   return priority >= category->threshold;
547 }
548
549 void xbt_log_parent_set(xbt_log_category_t cat,xbt_log_category_t parent) 
550 {
551         
552         xbt_assert0(cat,"NULL category to be given a parent");
553         xbt_assert1(parent,"The parent category of %s is NULL",cat->name);
554         
555         /* 
556          * if the threshold is initialized 
557          * unlink from current parent 
558          */
559         if(cat->threshold != xbt_log_priority_uninitialized){
560
561                 xbt_log_category_t* cpp = &parent->firstChild;
562         
563                 while(*cpp != cat && *cpp != NULL) {
564                         cpp = &(*cpp)->nextSibling;
565                 }
566                 
567                 xbt_assert(*cpp == cat);
568                 *cpp = cat->nextSibling;
569         }
570         
571         cat->parent = parent;
572         cat->nextSibling = parent->firstChild;
573         
574         parent->firstChild = cat;
575         
576         if (parent->threshold == xbt_log_priority_uninitialized){
577                 
578           _xbt_log_cat_init(parent,
579                             xbt_log_priority_uninitialized/* ignored*/);
580         }
581         
582         cat->threshold = parent->threshold;
583         
584         cat->isThreshInherited = 1;
585         
586 }
587
588 static void _set_inherited_thresholds(xbt_log_category_t cat) {
589         
590         
591   xbt_log_category_t child = cat->firstChild;
592   
593   for( ; child != NULL; child = child->nextSibling) {
594     if (child->isThreshInherited) {
595       if (cat != &_XBT_LOGV(log))
596         VERB3("Set category threshold of %s to %s (=%d)",
597               child->name,xbt_log_priority_names[cat->threshold],cat->threshold);
598       child->threshold = cat->threshold;
599       _set_inherited_thresholds(child);
600     }
601   }
602   
603  
604 }
605
606 void xbt_log_threshold_set(xbt_log_category_t   cat,
607                             e_xbt_log_priority_t threshold) {
608   cat->threshold = threshold;
609   cat->isThreshInherited = 0;
610  
611   _set_inherited_thresholds(cat);
612  
613 }
614
615 static xbt_log_setting_t _xbt_log_parse_setting(const char* control_string) {
616
617   xbt_log_setting_t set = xbt_new(s_xbt_log_setting_t,1);
618   const char *name, *dot, *eq;
619   
620   set->catname=NULL;
621   if (!*control_string) 
622     return set;
623   DEBUG1("Parse log setting '%s'",control_string);
624
625   control_string += strspn(control_string, " ");
626   name = control_string;
627   control_string += strcspn(control_string, ".= ");
628   dot = control_string;
629   control_string += strcspn(control_string, ":= ");
630   eq = control_string;
631   control_string += strcspn(control_string, " ");
632
633   xbt_assert1(*dot == '.' && (*eq == '=' || *eq == ':'),
634                "Invalid control string '%s'",control_string);
635
636   if (!strncmp(dot + 1, "thresh", (size_t)(eq - dot - 1))) {
637     int i;
638     char *neweq=xbt_strdup(eq+1);
639     char *p=neweq-1;
640     
641     while (*(++p) != '\0') {
642       if (*p >= 'a' && *p <= 'z') {
643         *p-='a'-'A';
644       }
645     }
646     
647     DEBUG1("New priority name = %s",neweq);
648     for (i=0; i<xbt_log_priority_infinite; i++) {
649       if (!strncmp(xbt_log_priority_names[i],neweq,p-eq)) {
650         DEBUG1("This is priority %d",i);
651         break;
652       }
653     }
654     if (i<xbt_log_priority_infinite) {
655       set->thresh= (e_xbt_log_priority_t) i;
656     } else {
657       THROW1(arg_error,0,
658              "Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)",eq+1);
659     }
660     free(neweq);
661   } else {
662     char buff[512];
663     snprintf(buff,min(512,eq - dot),"%s",dot+1);
664     THROW1(arg_error,0,"Unknown setting of the log category: '%s'",buff);
665   }
666   set->catname=(char*)xbt_malloc(dot - name+1);
667     
668   memcpy(set->catname,name,dot-name);
669   set->catname[dot-name]='\0'; /* Just in case */
670   DEBUG1("This is for cat '%s'", set->catname);
671   
672   return set;
673 }
674
675 static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat,char *name) {
676   xbt_log_category_t child;
677   
678   if (!strcmp(cat->name,name)) 
679     return cat;
680
681   for(child=cat->firstChild ; child != NULL; child = child->nextSibling) 
682     return _xbt_log_cat_searchsub(child,name);
683   
684   THROW1(not_found_error,0,"No such category: %s", name);
685 }
686
687 /**
688  * \ingroup XBT_log  
689  * \param control_string What to parse
690  *
691  * Typically passed a command-line argument. The string has the syntax:
692  *
693  *      ( [category] "." [keyword] ":" value (" ")... )...
694  *
695  * where [category] is one the category names (see \ref XBT_log_cats for a complete list) 
696  * and keyword is one of the following:
697  *
698  *    - thres: category's threshold priority. Possible values:
699  *             TRACE,DEBUG,VERBOSE,INFO,WARNING,ERROR,CRITICAL
700  *    - add or additivity: whether the logging actions must be passed to 
701  *      the parent category. 
702  *      Possible values: 0, 1, yes, no.
703  *      Default value: yes.
704  *             
705  */
706 void xbt_log_control_set(const char* control_string) {
707   xbt_log_setting_t set;
708
709   /* To split the string in commands, and the cursors */
710   xbt_dynar_t set_strings;
711   char *str;
712   int cpt;
713
714   if (!control_string)
715     return;
716   DEBUG1("Parse log settings '%s'",control_string);
717
718   /* some initialization if this is the first time that this get called */
719   if (xbt_log_settings == NULL)
720     xbt_log_settings = xbt_dynar_new(sizeof(xbt_log_setting_t),
721                                      _free_setting);
722
723   /* split the string, and remove empty entries */
724   set_strings=xbt_str_split_quoted(control_string);
725 #ifdef FIXME
726   xbt_dynar_foreach(set_strings,cpt,str) {
727     xbt_str_trim(str,NULL);
728     if (str[0]=='\0') {
729       xbt_dynar_cursor_rm(set_strings,&cpt);
730     }
731   }
732 #endif
733
734   if (xbt_dynar_length(set_strings) == 0) { /* vicious user! */
735     xbt_dynar_free(&set_strings);
736     return; 
737   }
738
739   /* Parse each entry and either use it right now (if the category was already
740      created), or store it for further use */
741   xbt_dynar_foreach(set_strings,cpt,str) {
742     xbt_log_category_t cat=NULL;
743     int found=0;
744     xbt_ex_t e;
745     
746     set = _xbt_log_parse_setting(str);
747
748     TRY {
749       cat = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname);
750       found = 1;
751     } CATCH(e) {
752       if (e.category != not_found_error)
753         RETHROW;
754       xbt_ex_free(e);
755       found = 0;
756     } 
757
758     if (found) {
759       DEBUG0("Apply directly");
760       xbt_log_threshold_set(cat,set->thresh);
761       _free_setting((void*)&set);
762     } else {
763
764       DEBUG0("Store for further application");
765       DEBUG1("push %p to the settings",(void*)set);
766       xbt_dynar_push(xbt_log_settings,&set);
767     }
768   }
769   xbt_dynar_free(&set_strings);
770
771
772 void xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app) {
773   if (cat->appender) {
774     if (cat->appender->free_)
775       cat->appender->free_(cat->appender);
776     free(cat->appender);
777   }
778   cat->appender = app;
779 }
780 void xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay) {
781   if (!cat->appender) {
782     WARN1("No appender to category %s. Setting the file appender as default",
783           cat->name);
784     xbt_log_appender_set(cat,xbt_log_appender_file_new(NULL));
785   }
786   if (cat->layout) {
787     if (cat->layout->free_) {
788       cat->layout->free_(cat->layout);
789       free(cat->layout);
790     }
791   }
792   cat->layout = lay;
793 }
794
795 void xbt_log_additivity_set(xbt_log_category_t cat, int additivity) {
796   cat->additivity = additivity;
797 }
798