Logo AND Algorithmique Numérique Distribuée

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