Logo AND Algorithmique Numérique Distribuée

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