Logo AND Algorithmique Numérique Distribuée

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