Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid multiple declaration on the same line/statement
[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;
243 typedef struct xbt_log_appender_s* xbt_log_appender_t;
244 typedef struct xbt_log_layout_s  s_xbt_log_layout_t;
245 typedef struct xbt_log_layout_s* xbt_log_layout_t;
246 typedef struct xbt_log_event_s  s_xbt_log_event_t;
247 typedef struct xbt_log_event_s* xbt_log_event_t;
248 typedef struct xbt_log_category_s  s_xbt_log_category_t;
249 typedef struct xbt_log_category_s* xbt_log_category_t;
250
251 /* Do NOT access any members of this structure directly. FIXME: move to private? */
252
253 struct xbt_log_category_s {
254   xbt_log_category_t parent;
255   xbt_log_category_t firstChild;
256   xbt_log_category_t nextSibling;
257   const char *name;
258   const char *description;
259   int initialized;
260   int threshold;
261   int isThreshInherited;
262   xbt_log_appender_t appender;
263   xbt_log_layout_t layout;
264   int additivity;
265 };
266
267 struct xbt_log_event_s {
268   xbt_log_category_t cat;
269   e_xbt_log_priority_t priority;
270   const char *fileName;
271   const char *functionName;
272   int lineNum;
273   va_list ap;
274   char *buffer;
275   int buffer_size;
276 };
277
278 /**
279  * \ingroup XBT_log_implem
280  * \param cat the category (not only its name, but the variable)
281  * \param thresholdPriority the priority
282  *
283  * Programatically alters a category's threshold priority (don't use).
284  */
285 XBT_PUBLIC(void) xbt_log_threshold_set(xbt_log_category_t cat, e_xbt_log_priority_t thresholdPriority);
286
287 /**
288  * \ingroup XBT_log_implem  
289  * \param cat the category (not only its name, but the variable)
290  * \param app the appender
291  *
292  * Programatically sets the category's appender. (the preferred interface is through xbt_log_control_set())
293  */
294 XBT_PUBLIC(void) xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app);
295 /**
296  * \ingroup XBT_log_implem  
297  * \param cat the category (not only its name, but the variable)
298  * \param lay the layout
299  *
300  * Programatically sets the category's layout. (the preferred interface is through xbt_log_control_set())
301  */
302 XBT_PUBLIC(void) xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay);
303
304 /**
305  * \ingroup XBT_log_implem  
306  * \param cat the category (not only its name, but the variable)
307  * \param additivity whether logging actions must be passed to parent.
308  *
309  * Programatically sets whether the logging actions must be passed to the parent category.
310  * (the preferred interface is through xbt_log_control_set())
311  */
312 XBT_PUBLIC(void) xbt_log_additivity_set(xbt_log_category_t cat, int additivity);
313
314 /** @brief create a new simple layout 
315  *
316  * This layout is not as flexible as the pattern one
317  */
318 XBT_PUBLIC(xbt_log_layout_t) xbt_log_layout_simple_new(char *arg);
319 XBT_PUBLIC(xbt_log_layout_t) xbt_log_layout_format_new(char *arg);
320 XBT_PUBLIC(xbt_log_appender_t) xbt_log_appender_file_new(char *arg);
321 XBT_PUBLIC(xbt_log_appender_t) xbt_log_appender2_file_new(char *arg,int roll);
322
323 /* ********************************** */
324 /* Functions that you shouldn't call  */
325 /* ********************************** */
326 XBT_PUBLIC(void) _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) XBT_ATTRIB_PRINTF(2, 3);
327 XBT_PUBLIC(int) _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority);
328
329 #ifdef DLL_EXPORT
330 XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT);
331 #else
332 // If we `dllexport` the root log category, MinGW does not want us to take its address with the error:
333 // > initializer element is not constant
334 // When using auto-import, MinGW is happy.
335 // We should handle this for non-root log categories as well.
336 extern s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT);
337 #endif
338
339 extern xbt_log_appender_t xbt_log_default_appender;
340 extern xbt_log_layout_t xbt_log_default_layout;
341
342 /* ********************** */
343 /* Public functions again */
344 /* ********************** */
345
346 /**
347  * \ingroup XBT_log 
348  * \param catName name of the category
349  * \param priority minimal priority to be enabled to return true (must be #e_xbt_log_priority_t)
350  * \hideinitializer
351  *
352  * Returns true if the given priority is enabled for the category.
353  * If you have expensive expressions that are computed outside of the log command and used only within it, you should
354  * make its evaluation conditional using this macro.
355  */
356 #define XBT_LOG_ISENABLED(catName, priority) \
357             _XBT_LOG_ISENABLEDV(_XBT_LOGV(catName), priority)
358
359 /*
360  * Helper function that implements XBT_LOG_ISENABLED.
361  *
362  * NOTES
363  * First part is a compile-time constant.
364  * Call to xbt_log_cat_init only happens once.
365  */
366 #define _XBT_LOG_ISENABLEDV(catv, priority)                  \
367        (priority >= XBT_LOG_STATIC_THRESHOLD                 \
368         && ((catv).initialized || _xbt_log_cat_init(&(catv), priority)) \
369         && priority >= (catv).threshold)
370
371 /*
372  * Internal Macros
373  * Some kludge macros to ease maintenance. See how they're used below.
374  *
375  * IMPLEMENTATION NOTE: To reduce the parameter passing overhead of an enabled message, the many parameters passed to
376  * the logging function are packed in a structure. Since these values will be usually be passed to at least 3 functions,
377  * this is a win.
378  * It also allows adding new values (such as a timestamp) without breaking code.
379  * Setting the LogEvent's valist member is done inside _log_logEvent.
380  */
381
382 /* Logging Macros */
383
384 #ifdef XBT_LOG_MAYDAY
385 # define XBT_CLOG(cat, prio, ...) \
386   _XBT_IF_ONE_ARG(_XBT_CLOG_ARG1, _XBT_CLOG_ARGN, __VA_ARGS__)(__VA_ARGS__)
387 # define _XBT_CLOG_ARG1(f) \
388   fprintf(stderr,"%s:%d:\n" f, __FILE__, __LINE__)
389 # define _XBT_CLOG_ARGN(f, ...) \
390   fprintf(stderr,"%s:%d:\n" f, __FILE__, __LINE__, __VA_ARGS__)
391 # define XBT_LOG(...) XBT_CLOG(0, __VA_ARGS__)
392 #else
393
394 // This code is duplicated to remove one level of indirection, working around a MSVC bug
395 // See: http://stackoverflow.com/questions/9183993/msvc-variadic-macro-expansion
396
397 # define XBT_CLOG(category, prio, ...) \
398   do {                                                                  \
399     if (_XBT_LOG_ISENABLEDV((category), prio)) {                        \
400       s_xbt_log_event_t _log_ev;                                        \
401       _log_ev.cat = &(category);                                        \
402       _log_ev.priority = (prio);                                        \
403       _log_ev.fileName = __FILE__;                                      \
404       _log_ev.functionName = __func__;                             \
405       _log_ev.lineNum = __LINE__;                                       \
406       _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
407     }                                                                   \
408   }  while (0)
409
410 # define XBT_LOG(prio,...) \
411   do {                                                                  \
412     if (_XBT_LOG_ISENABLEDV((*_simgrid_log_category__default), prio)) { \
413       s_xbt_log_event_t _log_ev;                                        \
414       _log_ev.cat = _simgrid_log_category__default;                     \
415       _log_ev.priority = (prio);                                        \
416       _log_ev.fileName = __FILE__;                                      \
417       _log_ev.functionName = __func__;                             \
418       _log_ev.lineNum = __LINE__;                                       \
419       _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
420     }                                                                   \
421   }  while (0)
422 #endif
423
424 /** @ingroup XBT_log
425  *  @hideinitializer
426  * \param categ the category on which to log
427  * \param ... the format string and its arguments
428  *  @brief Log an event at the DEBUG priority on the specified category with these args.
429  */
430 #define XBT_CDEBUG(categ, ...) \
431       do {                                                                  \
432         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_debug)) {            \
433           s_xbt_log_event_t _log_ev;                                        \
434           _log_ev.cat = &(_XBT_LOGV(categ));                                \
435           _log_ev.priority = xbt_log_priority_debug;                        \
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 VERB priority on the specified category with these args.
446  */
447 #define XBT_CVERB(categ, ...)  \
448       do {                                                                  \
449         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_verbose)) {          \
450           s_xbt_log_event_t _log_ev;                                        \
451           _log_ev.cat = &(_XBT_LOGV(categ));                                \
452           _log_ev.priority = xbt_log_priority_verbose;                      \
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 /** @ingroup XBT_log
461  *  @hideinitializer
462  *  @brief Log an event at the INFO priority on the specified category with these args.
463  */
464 #define XBT_CINFO(categ, ...) \
465       do {                                                                  \
466         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_info)) {             \
467           s_xbt_log_event_t _log_ev;                                        \
468           _log_ev.cat = &(_XBT_LOGV(categ));                                \
469           _log_ev.priority = xbt_log_priority_info;                         \
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 WARN priority on the specified category with these args.
481  */
482 #define XBT_CWARN(categ, ...) \
483       do {                                                                  \
484         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_warning)) {          \
485           s_xbt_log_event_t _log_ev;                                        \
486           _log_ev.cat = &(_XBT_LOGV(categ));                                \
487           _log_ev.priority = xbt_log_priority_warning;                      \
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
496 /** @ingroup XBT_log
497  *  @hideinitializer
498  *  @brief Log an event at the ERROR priority on the specified category with these args.
499  */
500 #define XBT_CERROR(categ, ...) \
501       do {                                                                  \
502         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_error)) {            \
503           s_xbt_log_event_t _log_ev;                                        \
504           _log_ev.cat = &(_XBT_LOGV(categ));                                \
505           _log_ev.priority = xbt_log_priority_error;                        \
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  *  @brief Log an event at the CRITICAL priority on the specified category with these args (CCRITICALn exists for any n<10).
516  */
517 #define XBT_CCRITICAL(categ, ...) \
518       do {                                                                  \
519         if (XBT_LOG_ISENABLED (categ, xbt_log_priority_critical)) {         \
520           s_xbt_log_event_t _log_ev;                                        \
521           _log_ev.cat = &(_XBT_LOGV(categ));                                \
522           _log_ev.priority = xbt_log_priority_critical;                     \
523           _log_ev.fileName = __FILE__;                                      \
524           _log_ev.functionName = __func__;                             \
525           _log_ev.lineNum = __LINE__;                                       \
526           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
527         }                                                                   \
528       }  while (0)
529
530 /** @ingroup XBT_log
531  *  @hideinitializer
532  * \param ... the format string and its arguments
533  *  @brief Log an event at the DEBUG priority on the default category with these args.
534  */
535 #define XBT_DEBUG(...) \
536       do {                                                                  \
537         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
538                             xbt_log_priority_debug)) {                  \
539           s_xbt_log_event_t _log_ev;                                        \
540           _log_ev.cat = _simgrid_log_category__default;                     \
541           _log_ev.priority = xbt_log_priority_debug;                        \
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 VERB priority on the default category with these args.
552  */
553 #define XBT_VERB(...) \
554       do {                                                                  \
555         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
556                             xbt_log_priority_verbose)) {                \
557           s_xbt_log_event_t _log_ev;                                        \
558           _log_ev.cat = _simgrid_log_category__default;                     \
559           _log_ev.priority = xbt_log_priority_verbose;                      \
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 INFO priority on the default category with these args.
570  */
571 #define XBT_INFO(...) \
572       do {                                                                  \
573         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
574                             xbt_log_priority_info)) {                   \
575           s_xbt_log_event_t _log_ev;                                        \
576           _log_ev.cat = _simgrid_log_category__default;                     \
577           _log_ev.priority = xbt_log_priority_info;                         \
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 WARN priority on the default category with these args.
588  */
589 #define XBT_WARN(...) \
590       do {                                                                  \
591         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
592                             xbt_log_priority_warning)) {                \
593           s_xbt_log_event_t _log_ev;                                        \
594           _log_ev.cat = _simgrid_log_category__default;                     \
595           _log_ev.priority = xbt_log_priority_warning;                      \
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 ERROR priority on the default category with these args.
606  */
607 #define XBT_ERROR(...) \
608       do {                                                                  \
609         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
610                             xbt_log_priority_error)) {                  \
611           s_xbt_log_event_t _log_ev;                                        \
612           _log_ev.cat = _simgrid_log_category__default;                     \
613           _log_ev.priority = xbt_log_priority_error;                        \
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 /** @ingroup XBT_log
622  *  @hideinitializer
623  *  @brief Log an event at the CRITICAL priority on the default category with these args.
624  */
625 #define XBT_CRITICAL(...) \
626       do {                                                                  \
627         if (_XBT_LOG_ISENABLEDV(*_simgrid_log_category__default,            \
628                             xbt_log_priority_critical)) {               \
629           s_xbt_log_event_t _log_ev;                                        \
630           _log_ev.cat = _simgrid_log_category__default;                     \
631           _log_ev.priority = xbt_log_priority_critical;                     \
632           _log_ev.fileName = __FILE__;                                      \
633           _log_ev.functionName = __func__;                             \
634           _log_ev.lineNum = __LINE__;                                       \
635           _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
636         }                                                                   \
637       }  while (0)
638
639 #define _XBT_IN_OUT(...) \
640   _XBT_IF_ONE_ARG(_XBT_IN_OUT_ARG1, _XBT_IN_OUT_ARGN, __VA_ARGS__)(__VA_ARGS__)
641 #define _XBT_IN_OUT_ARG1(fmt) \
642   XBT_LOG(xbt_log_priority_trace, fmt, __func__)
643 #define _XBT_IN_OUT_ARGN(fmt, ...) \
644   XBT_LOG(xbt_log_priority_trace, fmt, __func__, __VA_ARGS__)
645
646 /** @ingroup XBT_log
647  *  @hideinitializer
648  *  @brief Log at TRACE priority that we entered in current function, appending a user specified format.
649  */
650 #define XBT_IN(...) _XBT_IN_OUT(">> begin of %s" __VA_ARGS__)
651
652 /** @ingroup XBT_log
653  *  @hideinitializer
654  *  @brief Log at TRACE priority that we exited the current function, appending a user specified format.
655  */
656 #define XBT_OUT(...) _XBT_IN_OUT("<< end of %s" __VA_ARGS__)
657
658 /** @ingroup XBT_log
659  *  @hideinitializer
660  *  @brief Log at TRACE priority a message indicating that we reached that point, appending a user specified format.
661  */
662 #define XBT_HERE(...) XBT_LOG(xbt_log_priority_trace, "-- was here" __VA_ARGS__)
663
664 SG_END_DECL()
665 #endif                          /* ! _XBT_LOG_H_ */