Logo AND Algorithmique Numérique Distribuée

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