Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a65699c37e5925d9f6063c6fc11c0e681c042e8e
[simgrid.git] / include / xbt / log.h
1 /* log - a generic logging facility in the spirit of log4j                  */
2
3 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 /** @addtogroup XBT_log
9  *  @brief A generic logging facility in the spirit of log4j (grounding feature)
10  *
11  */
12
13 /** @defgroup XBT_log_cats Existing log categories
14  *  @ingroup XBT_log
15  *  @brief (automatically extracted)
16  *
17  *  This is the list of all existing log categories in SimGrid.
18  *  This list is automatically extracted from the source code by the tools/doxygen/xbt_log_extract_hierarchy.pl utility.
19  *
20  *  It should thus contain every categories that are defined in the SimGrid library.
21  *  If you want to see the one defined in your code in addition, provide `--help-logs` on the command line of your
22  * simulator.
23  */
24
25 /* XBT_LOG_MAYDAY: define this to replace the logging facilities with basic
26    printf function. Useful to debug the logging facilities themselves, or to not make source analysis tools mad */
27 //#define XBT_LOG_MAYDAY
28
29 #ifndef XBT_LOG_H
30 #define XBT_LOG_H
31
32 #include <stdarg.h>
33 #include <stddef.h> /* NULL */
34 #include <xbt/misc.h>
35 SG_BEGIN_DECL()
36 /**@brief Log priorities
37  * @ingroup XBT_log
38  *
39  * The different existing priorities.
40  */
41 typedef enum {
42   //! @cond
43   xbt_log_priority_none = 0,           /** used internally (don't poke with)*/
44   //! @endcond
45   xbt_log_priority_trace = 1,          /**< enter and return of some functions */
46   xbt_log_priority_debug = 2,          /**< crufty output  */
47   xbt_log_priority_verbose = 3,        /**< verbose output for the user wanting more */
48   xbt_log_priority_info = 4,           /**< output about the regular functionning */
49   xbt_log_priority_warning = 5,        /**< minor issue encountered */
50   xbt_log_priority_error = 6,          /**< issue encountered */
51   xbt_log_priority_critical = 7,       /**< major issue encountered */
52
53   xbt_log_priority_infinite = 8,       /**< value for XBT_LOG_STATIC_THRESHOLD to not log */
54
55   //! @cond
56   xbt_log_priority_uninitialized = -1  /* used internally (don't poke with) */
57   //! @endcond
58 } e_xbt_log_priority_t;
59
60 /*
61  * define NLOG to disable at compilation time any logging request
62  * define NDEBUG to disable at compilation time any logging request of priority below VERBOSE
63  */
64
65 /**
66  * @def XBT_LOG_STATIC_THRESHOLD
67  * @ingroup XBT_log
68  *
69  * All logging requests with priority < XBT_LOG_STATIC_THRESHOLD are disabled at compile time, i.e., compiled out.
70  */
71 #ifdef NLOG
72 #  define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_infinite
73 #else
74
75 #  ifdef NDEBUG
76 #    define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_verbose
77 #  else                         /* !NLOG && !NDEBUG */
78
79 #    ifndef XBT_LOG_STATIC_THRESHOLD
80 #      define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_none
81 #    endif                      /* !XBT_LOG_STATIC_THRESHOLD */
82 #  endif                        /* NDEBUG */
83 #endif                          /* !defined(NLOG) */
84
85 /* Transforms a category name to a global variable name. */
86 #define _XBT_LOGV(cat) _XBT_LOG_CONCAT(_simgrid_log_category__, cat)
87 #define _XBT_LOGV_CTOR(cat) _XBT_LOG_CONCAT2(_XBT_LOGV(cat), __constructor__)
88 #define _XBT_LOG_CONCAT(x, y) x ## y
89 #define _XBT_LOG_CONCAT2(x, y) _XBT_LOG_CONCAT(x, y)
90
91 /* The root of the category hierarchy. */
92 #define XBT_LOG_ROOT_CAT   root
93
94 /* The whole tree of categories is connected by setting the address of the parent category as a field of the child one.
95  * This is normally done at the first use of the category.
96  *
97  * It is however necessary to make this connections as early as possible, if we want the category to be listed by
98  * --help-log-categories. We use constructor attributes for these initializations to take place automatically before the
99  * start of main().
100  */
101
102 /* XBT_LOG_NEW_SUBCATEGORY_helper:
103  * Implementation of XBT_LOG_NEW_SUBCATEGORY, which must declare "extern parent" in addition to avoid an extra
104  * declaration of root when XBT_LOG_NEW_SUBCATEGORY is called by XBT_LOG_NEW_CATEGORY */
105 #define XBT_LOG_NEW_SUBCATEGORY_helper(catName, parent, desc)                                                          \
106   SG_BEGIN_DECL()                                                                                                      \
107   extern void _XBT_LOGV_CTOR(catName)(void) XBT_ATTRIB_CONSTRUCTOR(600);                                               \
108   void _XBT_LOGV_CTOR(catName)(void)                                                                                   \
109   {                                                                                                                    \
110     XBT_LOG_EXTERNAL_CATEGORY(catName);                                                                                \
111     if (!_XBT_LOGV(catName).initialized) {                                                                             \
112       _xbt_log_cat_init(&_XBT_LOGV(catName), xbt_log_priority_uninitialized);                                          \
113     }                                                                                                                  \
114   }                                                                                                                    \
115   SG_END_DECL()                                                                                                        \
116   XBT_EXPORT_NO_IMPORT s_xbt_log_category_t _XBT_LOGV(catName) = {                                                     \
117       &_XBT_LOGV(parent),                                                                                              \
118       NULL /* firstChild */,                                                                                           \
119       NULL /* nextSibling */,                                                                                          \
120       #catName,                                                                                                        \
121       desc,                                                                                                            \
122       0 /*initialized */,                                                                                              \
123       xbt_log_priority_uninitialized /* threshold */,                                                                  \
124       1 /* isThreshInherited */,                                                                                       \
125       NULL /* appender */,                                                                                             \
126       NULL /* layout */,                                                                                               \
127       1 /* additivity */                                                                                               \
128   }
129
130 /**
131  * @ingroup XBT_log
132  * @param catName name of new category
133  * @param parent father of the new category in the tree
134  * @param desc string describing the purpose of this category
135  * @hideinitializer
136  *
137  * Defines a new subcategory of the parent.
138  */
139 #define XBT_LOG_NEW_SUBCATEGORY(catName, parent, desc)    \
140   XBT_LOG_EXTERNAL_CATEGORY(parent);                      \
141   XBT_LOG_NEW_SUBCATEGORY_helper(catName, parent, desc)
142
143 /**
144  * @ingroup XBT_log
145  * @param catName name of new category
146  * @param desc string describing the purpose of this category
147  * @hideinitializer
148  *
149  * Creates a new subcategory of the root category.
150  */
151 # define XBT_LOG_NEW_CATEGORY(catName,desc)  \
152    XBT_LOG_NEW_SUBCATEGORY_helper(catName, XBT_LOG_ROOT_CAT, desc)
153
154 /**
155  * @ingroup XBT_log
156  * @param cname name of the cat
157  * @hideinitializer
158  *
159  * Indicates which category is the default one.
160  */
161
162 #if defined(XBT_LOG_MAYDAY) /*|| defined (NLOG) * turning logging off */
163 # define XBT_LOG_DEFAULT_CATEGORY(cname)
164 #else
165 #define XBT_LOG_DEFAULT_CATEGORY(cname)                                                                                \
166   XBT_ATTRIB_UNUSED static xbt_log_category_t _XBT_LOGV(default) = &_XBT_LOGV(cname)
167 #endif
168
169 /**
170  * @ingroup XBT_log
171  * @param cname name of the cat
172  * @param desc string describing the purpose of this category
173  * @hideinitializer
174  *
175  * Creates a new subcategory of the root category and makes it the default (used by macros that don't explicitly
176  * specify a category).
177  */
178 # define XBT_LOG_NEW_DEFAULT_CATEGORY(cname,desc)        \
179     XBT_LOG_NEW_CATEGORY(cname,desc);                   \
180     XBT_LOG_DEFAULT_CATEGORY(cname)
181
182 /**
183  * @ingroup XBT_log
184  * @param cname name of the cat
185  * @param parent name of the parent
186  * @param desc string describing the purpose of this category
187  * @hideinitializer
188  *
189  * Creates a new subcategory of the parent category and makes it the default
190  * (used by macros that don't explicitly specify a category).
191  */
192 #define XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cname, parent, desc) \
193     XBT_LOG_NEW_SUBCATEGORY(cname, parent, desc);            \
194     XBT_LOG_DEFAULT_CATEGORY(cname)
195
196 /**
197  * @ingroup XBT_log
198  * @param cname name of the cat
199  * @hideinitializer
200  *
201  * Indicates that a category you'll use in this file (e.g., to get subcategories of it) really lives in another file.
202  */
203
204 #define XBT_LOG_EXTERNAL_CATEGORY(cname) \
205    extern s_xbt_log_category_t _XBT_LOGV(cname)
206
207 /**
208  * @ingroup XBT_log
209  * @param cname name of the cat
210  * @hideinitializer
211  *
212  * Indicates that the default category of this file was declared in another file.
213  */
214
215 #define XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(cname) \
216    XBT_LOG_EXTERNAL_CATEGORY(cname);\
217    XBT_LOG_DEFAULT_CATEGORY(cname)
218
219 /* Functions you may call */
220
221 XBT_PUBLIC void xbt_log_control_set(const char* cs);
222
223 /* Forward declarations */
224 typedef struct xbt_log_appender_s  s_xbt_log_appender_t;
225 typedef s_xbt_log_appender_t* xbt_log_appender_t;
226 typedef struct xbt_log_layout_s  s_xbt_log_layout_t;
227 typedef s_xbt_log_layout_t* xbt_log_layout_t;
228 typedef struct xbt_log_event_s  s_xbt_log_event_t;
229 typedef s_xbt_log_event_t* xbt_log_event_t;
230 typedef struct xbt_log_category_s  s_xbt_log_category_t;
231 typedef s_xbt_log_category_t* xbt_log_category_t;
232
233 /* Do NOT access any members of this structure directly. FIXME: move to private? */
234
235 struct xbt_log_category_s {
236   xbt_log_category_t parent;
237   xbt_log_category_t firstChild;
238   xbt_log_category_t nextSibling;
239   const char *name;
240   const char *description;
241   int initialized;
242   int threshold;
243   int isThreshInherited;
244   xbt_log_appender_t appender;
245   xbt_log_layout_t layout;
246   int additivity;
247 };
248
249 struct xbt_log_event_s {
250   xbt_log_category_t cat;
251   e_xbt_log_priority_t priority;
252   const char *fileName;
253   const char *functionName;
254   int lineNum;
255   va_list ap;
256   char *buffer;
257   int buffer_size;
258 };
259
260 /**
261  * @ingroup XBT_log_implem
262  * @param cat the category (not only its name, but the variable)
263  * @param thresholdPriority the priority
264  *
265  * Programatically alters a category's threshold priority (don't use).
266  */
267 XBT_PUBLIC void xbt_log_threshold_set(xbt_log_category_t cat, e_xbt_log_priority_t thresholdPriority);
268
269 /**
270  * @ingroup XBT_log_implem
271  * @param cat the category (not only its name, but the variable)
272  * @param app the appender
273  *
274  * Programatically sets the category's appender. (the preferred interface is through xbt_log_control_set())
275  */
276 XBT_PUBLIC void xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app);
277 /**
278  * @ingroup XBT_log_implem
279  * @param cat the category (not only its name, but the variable)
280  * @param lay the layout
281  *
282  * Programatically sets the category's layout. (the preferred interface is through xbt_log_control_set())
283  */
284 XBT_PUBLIC void xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay);
285
286 /**
287  * @ingroup XBT_log_implem
288  * @param cat the category (not only its name, but the variable)
289  * @param additivity whether logging actions must be passed to parent.
290  *
291  * Programatically sets whether the logging actions must be passed to the parent category.
292  * (the preferred interface is through xbt_log_control_set())
293  */
294 XBT_PUBLIC void xbt_log_additivity_set(xbt_log_category_t cat, int additivity);
295
296 /** @brief create a new simple layout
297  *
298  * This layout is not as flexible as the pattern one
299  */
300 XBT_PUBLIC xbt_log_layout_t xbt_log_layout_simple_new(const char* arg);
301 XBT_PUBLIC xbt_log_layout_t xbt_log_layout_format_new(const char* arg);
302 XBT_PUBLIC xbt_log_appender_t xbt_log_appender_file_new(const char* arg);
303 XBT_PUBLIC xbt_log_appender_t xbt_log_appender2_file_new(const char* arg, int roll);
304
305 /* ********************************** */
306 /* Functions that you shouldn't call  */
307 /* ********************************** */
308 XBT_PUBLIC void xbt_log_init(int* argc, char** argv);
309 XBT_PUBLIC void _xbt_log_event_log(xbt_log_event_t ev, const char* fmt, ...) XBT_ATTRIB_PRINTF(2, 3);
310 XBT_PUBLIC int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority);
311
312 #ifdef DLL_EXPORT
313 XBT_PUBLIC_DATA s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT);
314 #else
315 // If we `dllexport` the root log category, MinGW does not want us to take its address with the error:
316 // > initializer element is not constant
317 // When using auto-import, MinGW is happy.
318 // We should handle this for non-root log categories as well.
319 extern s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT);
320 #endif
321
322 extern xbt_log_appender_t xbt_log_default_appender;
323 extern xbt_log_layout_t xbt_log_default_layout;
324
325 /* ********************** */
326 /* Public functions again */
327 /* ********************** */
328
329 /**
330  * @ingroup XBT_log
331  * @param catName name of the category
332  * @param priority minimal priority to be enabled to return true (must be #e_xbt_log_priority_t)
333  * @hideinitializer
334  *
335  * Returns true if the given priority is enabled for the category.
336  * If you have expensive expressions that are computed outside of the log command and used only within it, you should
337  * make its evaluation conditional using this macro.
338  */
339 #define XBT_LOG_ISENABLED(catName, priority) \
340             _XBT_LOG_ISENABLEDV(_XBT_LOGV(catName), priority)
341
342 /*
343  * Helper function that implements XBT_LOG_ISENABLED.
344  *
345  * NOTES
346  * First part is a compile-time constant.
347  * Call to xbt_log_cat_init only happens once.
348  */
349 #define _XBT_LOG_ISENABLEDV(catv, priority)                  \
350        (priority >= XBT_LOG_STATIC_THRESHOLD                 \
351         && ((catv).initialized || _xbt_log_cat_init(&(catv), priority)) \
352         && priority >= (catv).threshold)
353
354 /*
355  * Internal Macros
356  * Some kludge macros to ease maintenance. See how they're used below.
357  *
358  * IMPLEMENTATION NOTE: To reduce the parameter passing overhead of an enabled message, the many parameters passed to
359  * the logging function are packed in a structure. Since these values will be usually be passed to at least 3 functions,
360  * this is a win.
361  * It also allows adding new values (such as a timestamp) without breaking code.
362  * Setting the LogEvent's valist member is done inside _log_logEvent.
363  */
364
365 /* Logging Macros */
366
367 #ifdef XBT_LOG_MAYDAY
368 # define XBT_CLOG(cat, prio, ...) \
369   _XBT_IF_ONE_ARG(_XBT_CLOG_ARG1, _XBT_CLOG_ARGN, __VA_ARGS__)(__VA_ARGS__)
370 # define _XBT_CLOG_ARG1(f) \
371   fprintf(stderr,"%s:%d:\n" f, __FILE__, __LINE__)
372 # define _XBT_CLOG_ARGN(f, ...) \
373   fprintf(stderr,"%s:%d:\n" f, __FILE__, __LINE__, __VA_ARGS__)
374 # define XBT_LOG(...) XBT_CLOG(0, __VA_ARGS__)
375 #else
376
377 // This code is duplicated to remove one level of indirection, working around a MSVC bug
378 // See: http://stackoverflow.com/questions/9183993/msvc-variadic-macro-expansion
379
380 # define XBT_CLOG(category, prio, ...) \
381   do {                                                                  \
382     if (_XBT_LOG_ISENABLEDV((category), prio)) {                        \
383       s_xbt_log_event_t _log_ev;                                        \
384       _log_ev.cat = &(category);                                        \
385       _log_ev.priority = (prio);                                        \
386       _log_ev.fileName = __FILE__;                                      \
387       _log_ev.functionName = __func__;                             \
388       _log_ev.lineNum = __LINE__;                                       \
389       _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
390     }                                                                   \
391   }  while (0)
392
393 # define XBT_LOG(prio,...) \
394   do {                                                                  \
395     if (_XBT_LOG_ISENABLEDV((*_simgrid_log_category__default), prio)) { \
396       s_xbt_log_event_t _log_ev;                                        \
397       _log_ev.cat = _simgrid_log_category__default;                     \
398       _log_ev.priority = (prio);                                        \
399       _log_ev.fileName = __FILE__;                                      \
400       _log_ev.functionName = __func__;                             \
401       _log_ev.lineNum = __LINE__;                                       \
402       _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
403     }                                                                   \
404   }  while (0)
405 #endif
406
407 /** @ingroup XBT_log
408  *  @hideinitializer
409  * @param categ the category on which to log
410  * @param ... the format string and its arguments
411  *  @brief Log an event at the DEBUG priority on the specified category with these args.
412  */
413 #define XBT_CDEBUG(categ, ...) \
414       do {                                                                  \
415         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_debug)) {            \
416           s_xbt_log_event_t _log_ev;                                        \
417           _log_ev.cat = &(_XBT_LOGV(categ));                                \
418           _log_ev.priority = xbt_log_priority_debug;                        \
419           _log_ev.fileName = __FILE__;                                      \
420           _log_ev.functionName = __func__;                             \
421           _log_ev.lineNum = __LINE__;                                       \
422           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
423         }                                                                   \
424       }  while (0)
425
426 /** @ingroup XBT_log
427  *  @hideinitializer
428  *  @brief Log an event at the VERB priority on the specified category with these args.
429  */
430 #define XBT_CVERB(categ, ...)  \
431       do {                                                                  \
432         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_verbose)) {          \
433           s_xbt_log_event_t _log_ev;                                        \
434           _log_ev.cat = &(_XBT_LOGV(categ));                                \
435           _log_ev.priority = xbt_log_priority_verbose;                      \
436           _log_ev.fileName = __FILE__;                                      \
437           _log_ev.functionName = __func__;                             \
438           _log_ev.lineNum = __LINE__;                                       \
439           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
440         }                                                                   \
441       }  while (0)
442
443 /** @ingroup XBT_log
444  *  @hideinitializer
445  *  @brief Log an event at the INFO priority on the specified category with these args.
446  */
447 #define XBT_CINFO(categ, ...) \
448       do {                                                                  \
449         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_info)) {             \
450           s_xbt_log_event_t _log_ev;                                        \
451           _log_ev.cat = &(_XBT_LOGV(categ));                                \
452           _log_ev.priority = xbt_log_priority_info;                         \
453           _log_ev.fileName = __FILE__;                                      \
454           _log_ev.functionName = __func__;                             \
455           _log_ev.lineNum = __LINE__;                                       \
456           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
457         }                                                                   \
458       }  while (0)
459
460
461 /** @ingroup XBT_log
462  *  @hideinitializer
463  *  @brief Log an event at the WARN priority on the specified category with these args.
464  */
465 #define XBT_CWARN(categ, ...) \
466       do {                                                                  \
467         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_warning)) {          \
468           s_xbt_log_event_t _log_ev;                                        \
469           _log_ev.cat = &(_XBT_LOGV(categ));                                \
470           _log_ev.priority = xbt_log_priority_warning;                      \
471           _log_ev.fileName = __FILE__;                                      \
472           _log_ev.functionName = __func__;                             \
473           _log_ev.lineNum = __LINE__;                                       \
474           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
475         }                                                                   \
476       }  while (0)
477
478
479 /** @ingroup XBT_log
480  *  @hideinitializer
481  *  @brief Log an event at the ERROR priority on the specified category with these args.
482  */
483 #define XBT_CERROR(categ, ...) \
484       do {                                                                  \
485         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_error)) {            \
486           s_xbt_log_event_t _log_ev;                                        \
487           _log_ev.cat = &(_XBT_LOGV(categ));                                \
488           _log_ev.priority = xbt_log_priority_error;                        \
489           _log_ev.fileName = __FILE__;                                      \
490           _log_ev.functionName = __func__;                             \
491           _log_ev.lineNum = __LINE__;                                       \
492           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
493         }                                                                   \
494       }  while (0)
495
496 /** @ingroup XBT_log
497  *  @hideinitializer
498  *  @brief Log an event at the CRITICAL priority on the specified category with these args (CCRITICALn exists for any n<10).
499  */
500 #define XBT_CCRITICAL(categ, ...) \
501       do {                                                                  \
502         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_critical)) {         \
503           s_xbt_log_event_t _log_ev;                                        \
504           _log_ev.cat = &(_XBT_LOGV(categ));                                \
505           _log_ev.priority = xbt_log_priority_critical;                     \
506           _log_ev.fileName = __FILE__;                                      \
507           _log_ev.functionName = __func__;                             \
508           _log_ev.lineNum = __LINE__;                                       \
509           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
510         }                                                                   \
511       }  while (0)
512
513 /** @ingroup XBT_log
514  *  @hideinitializer
515  *  @param ... the format string and its arguments
516  *  @brief Log an event at the DEBUG priority on the default category with these args.
517  */
518 #define XBT_DEBUG(...) \
519       do {                                                                  \
520         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
521                             xbt_log_priority_debug)) {                  \
522           s_xbt_log_event_t _log_ev;                                        \
523           _log_ev.cat = _simgrid_log_category__default;                     \
524           _log_ev.priority = xbt_log_priority_debug;                        \
525           _log_ev.fileName = __FILE__;                                      \
526           _log_ev.functionName = __func__;                              \
527           _log_ev.lineNum = __LINE__;                                       \
528           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
529         }                                                                   \
530       }  while (0)
531
532 /** @ingroup XBT_log
533  *  @hideinitializer
534  *  @brief Log an event at the VERB priority on the default category with these args.
535  */
536 #define XBT_VERB(...) \
537       do {                                                                  \
538         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
539                             xbt_log_priority_verbose)) {                \
540           s_xbt_log_event_t _log_ev;                                        \
541           _log_ev.cat = _simgrid_log_category__default;                     \
542           _log_ev.priority = xbt_log_priority_verbose;                      \
543           _log_ev.fileName = __FILE__;                                      \
544           _log_ev.functionName = __func__;                             \
545           _log_ev.lineNum = __LINE__;                                       \
546           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
547         }                                                                   \
548       }  while (0)
549
550 /** @ingroup XBT_log
551  *  @hideinitializer
552  *  @brief Log an event at the INFO priority on the default category with these args.
553  */
554 #define XBT_INFO(...) \
555       do {                                                                  \
556         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
557                             xbt_log_priority_info)) {                   \
558           s_xbt_log_event_t _log_ev;                                        \
559           _log_ev.cat = _simgrid_log_category__default;                     \
560           _log_ev.priority = xbt_log_priority_info;                         \
561           _log_ev.fileName = __FILE__;                                      \
562           _log_ev.functionName = __func__;                             \
563           _log_ev.lineNum = __LINE__;                                       \
564           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
565         }                                                                   \
566       }  while (0)
567
568 /** @ingroup XBT_log
569  *  @hideinitializer
570  *  @brief Log an event at the WARN priority on the default category with these args.
571  */
572 #define XBT_WARN(...) \
573       do {                                                                  \
574         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
575                             xbt_log_priority_warning)) {                \
576           s_xbt_log_event_t _log_ev;                                        \
577           _log_ev.cat = _simgrid_log_category__default;                     \
578           _log_ev.priority = xbt_log_priority_warning;                      \
579           _log_ev.fileName = __FILE__;                                      \
580           _log_ev.functionName = __func__;                             \
581           _log_ev.lineNum = __LINE__;                                       \
582           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
583         }                                                                   \
584       }  while (0)
585
586 /** @ingroup XBT_log
587  *  @hideinitializer
588  *  @brief Log an event at the ERROR priority on the default category with these args.
589  */
590 #define XBT_ERROR(...) \
591       do {                                                                  \
592         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
593                             xbt_log_priority_error)) {                  \
594           s_xbt_log_event_t _log_ev;                                        \
595           _log_ev.cat = _simgrid_log_category__default;                     \
596           _log_ev.priority = xbt_log_priority_error;                        \
597           _log_ev.fileName = __FILE__;                                      \
598           _log_ev.functionName = __func__;                             \
599           _log_ev.lineNum = __LINE__;                                       \
600           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
601         }                                                                   \
602       }  while (0)
603
604 /** @ingroup XBT_log
605  *  @hideinitializer
606  *  @brief Log an event at the CRITICAL priority on the default category with these args.
607  */
608 #define XBT_CRITICAL(...) \
609       do {                                                                  \
610         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
611                             xbt_log_priority_critical)) {               \
612           s_xbt_log_event_t _log_ev;                                        \
613           _log_ev.cat = _simgrid_log_category__default;                     \
614           _log_ev.priority = xbt_log_priority_critical;                     \
615           _log_ev.fileName = __FILE__;                                      \
616           _log_ev.functionName = __func__;                             \
617           _log_ev.lineNum = __LINE__;                                       \
618           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
619         }                                                                   \
620       }  while (0)
621
622 #define _XBT_IN_OUT(...) \
623   _XBT_IF_ONE_ARG(_XBT_IN_OUT_ARG1, _XBT_IN_OUT_ARGN, __VA_ARGS__)(__VA_ARGS__)
624 #define _XBT_IN_OUT_ARG1(fmt) \
625   XBT_LOG(xbt_log_priority_trace, fmt, __func__)
626 #define _XBT_IN_OUT_ARGN(fmt, ...) \
627   XBT_LOG(xbt_log_priority_trace, fmt, __func__, __VA_ARGS__)
628
629 /** @ingroup XBT_log
630  *  @hideinitializer
631  *  @brief Log at TRACE priority that we entered in current function, appending a user specified format.
632  */
633 #define XBT_IN(...) _XBT_IN_OUT(">> begin of %s" __VA_ARGS__)
634
635 /** @ingroup XBT_log
636  *  @hideinitializer
637  *  @brief Log at TRACE priority that we exited the current function, appending a user specified format.
638  */
639 #define XBT_OUT(...) _XBT_IN_OUT("<< end of %s" __VA_ARGS__)
640
641 /** @ingroup XBT_log
642  *  @hideinitializer
643  *  @brief Log at TRACE priority a message indicating that we reached that point, appending a user specified format.
644  */
645 #define XBT_HERE(...) XBT_LOG(xbt_log_priority_trace, "-- was here" __VA_ARGS__)
646
647 /** @ingroup XBT_log
648  *  @hideinitializer
649  *  @brief Log help messages through category xbt.xbt_help.
650  */
651 #define XBT_HELP(...) XBT_CINFO(xbt_help, __VA_ARGS__)
652
653 SG_END_DECL()
654 #endif                          /* ! _XBT_LOG_H_ */