Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
consider log to windows dll
[simgrid.git] / include / xbt / log.h
1 /* $Id$ */
2
3 /* log - a generic logging facility in the spirit of log4j                  */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 /** @addtogroup XBT_log
11  *  @brief A generic logging facility in the spirit of log4j (grounding feature)
12  *
13  *
14  */
15  
16 /** \defgroup XBT_log_cats Existing log categories
17  *  \ingroup XBT_log
18  *  \brief (automatically extracted) 
19  *     
20  *  This is the list of all existing log categories in SimGrid.
21  *  This list was automatically extracted from the source code by
22  *  the src/xbt_log_extract_hierarchy utility.
23  *     
24  *  You can thus be certain that it is uptodate, but it may somehow
25  *  lack a final manual touch.
26  *  Anyway, nothing's perfect ;)
27  */
28
29 /* XBT_LOG_MAYDAY: define this to replace the logging facilities with basic
30    printf function. Useful to debug the logging facilities themselves */
31 #undef XBT_LOG_MAYDAY
32 /*#define XBT_LOG_MAYDAY*/
33
34 #ifndef _XBT_LOG_H_
35 #define _XBT_LOG_H_
36
37 #include "xbt/misc.h"
38
39 #include <stdarg.h>
40 SG_BEGIN_DECL()
41 /**\brief Log priorities
42  * \ingroup XBT_log
43  *
44  * The different existing priorities.
45 */
46 typedef enum {
47   xbt_log_priority_none          = 0,  /* used internally (don't poke with) */
48   xbt_log_priority_trace         = 1,  /**< enter and return of some functions */
49   xbt_log_priority_debug         = 2,  /**< crufty output  */
50   xbt_log_priority_verbose       = 3,  /**< verbose output for the user wanting more */
51   xbt_log_priority_info          = 4,  /**< output about the regular functionning */
52   xbt_log_priority_warning       = 5,  /**< minor issue encountered */
53   xbt_log_priority_error         = 6,  /**< issue encountered */
54   xbt_log_priority_critical      = 7,  /**< major issue encountered */
55
56   xbt_log_priority_infinite      = 8,  /**< value for XBT_LOG_STATIC_THRESHOLD to not log */
57
58   xbt_log_priority_uninitialized = -1  /* used internally (don't poke with) */
59 } e_xbt_log_priority_t;
60               
61
62 /*
63  * define NLOG to disable at compilation time any logging request
64  * define NDEBUG to disable at compilation time any logging request of priority below INFO
65  */
66
67
68 /**
69  * @def XBT_LOG_STATIC_THRESHOLD
70  * @ingroup XBT_log
71  *
72  * All logging requests with priority < XBT_LOG_STATIC_THRESHOLD are disabled at
73  * compile time, i.e., compiled out.
74  */
75 #ifdef NLOG
76 #  define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_infinite
77 #else
78
79 #  ifdef NDEBUG
80 #    define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_verbose
81 #  else /* !NLOG && !NDEBUG */
82
83 #    ifndef XBT_LOG_STATIC_THRESHOLD
84 #      define XBT_LOG_STATIC_THRESHOLD xbt_log_priority_none
85 #    endif /* !XBT_LOG_STATIC_THRESHOLD */
86 #  endif /* NDEBUG */
87 #endif /* !defined(NLOG) */
88
89 /* Transforms a category name to a global variable name. */
90 #define _XBT_LOGV(cat)   _XBT_LOG_CONCAT(_gras_this_log_category_does_not_exist__, cat)
91 #define _XBT_LOG_CONCAT(x,y) x ## y
92
93 /* The root of the category hierarchy. */
94 #define XBT_LOG_ROOT_CAT   root
95
96 /* XBT_LOG_NEW_SUBCATEGORY_helper:
97  * Implementation of XBT_LOG_NEW_SUBCATEGORY, which must declare "extern parent" in addition
98  * to avoid an extra declaration of root when XBT_LOG_NEW_SUBCATEGORY is called by
99  * XBT_LOG_NEW_CATEGORY */
100 #define XBT_LOG_NEW_SUBCATEGORY_helper(catName, parent, desc) \
101     XBT_PUBLIC_NO_IMPORT(s_xbt_log_category_t) _XBT_LOGV(catName) = {       \
102         &_XBT_LOGV(parent), 0, 0,                    \
103         #catName, xbt_log_priority_uninitialized, 1, \
104         0, 1                                          \
105     }
106 /**
107  * \ingroup XBT_log
108  * \param catName name of new category
109  * \param parent father of the new category in the tree
110  * \param desc string describing the purpose of this category
111  * \hideinitializer
112  *
113  * Defines a new subcategory of the parent. 
114  */
115 #define XBT_LOG_NEW_SUBCATEGORY(catName, parent, desc)    \
116     extern s_xbt_log_category_t _XBT_LOGV(parent); \
117     XBT_LOG_NEW_SUBCATEGORY_helper(catName, parent, desc) \
118
119 /**
120  * \ingroup XBT_log  
121  * \param catName name of new category
122  * \param desc string describing the purpose of this category
123  * \hideinitializer
124  *
125  * Creates a new subcategory of the root category.
126  */
127 #define XBT_LOG_NEW_CATEGORY(catName,desc)  XBT_LOG_NEW_SUBCATEGORY_helper(catName, XBT_LOG_ROOT_CAT, desc)
128
129 /**
130  * \ingroup XBT_log  
131  * \param cname name of the cat
132  * \hideinitializer
133  *
134  * Indicates which category is the default one.
135  */
136
137 #if defined(XBT_LOG_MAYDAY) /*|| defined (NLOG) * turning logging off */
138 # define XBT_LOG_DEFAULT_CATEGORY(cname)
139 #else
140 # define XBT_LOG_DEFAULT_CATEGORY(cname) \
141          static xbt_log_category_t _XBT_LOGV(default) _XBT_GNUC_UNUSED = &_XBT_LOGV(cname) 
142 #endif
143
144 /**
145  * \ingroup XBT_log  
146  * \param cname name of the cat
147  * \param desc string describing the purpose of this category
148  * \hideinitializer
149  *
150  * Creates a new subcategory of the root category and makes it the default
151  * (used by macros that don't explicitly specify a category).
152  */
153
154 #if (defined(_WIN32) && !defined(DLL_STATIC))
155 # define XBT_LOG_NEW_ROOT_SUBCATEGORY(cname,desc) \
156         XBT_PUBLIC_NO_IMPORT(s_xbt_log_category_t) _XBT_LOGV(cname) = {       \
157         0, 0, 0,                    \
158                 #cname, xbt_log_priority_uninitialized, 1, \
159         0, 1                                          \
160     }
161     
162 # define XBT_LOG_NEW_DEFAULT_CATEGORY(cname,desc)        \
163         XBT_LOG_NEW_ROOT_SUBCATEGORY(cname,desc); \
164         XBT_LOG_DEFAULT_CATEGORY(cname)
165     
166 #else
167 # define XBT_LOG_NEW_DEFAULT_CATEGORY(cname,desc)        \
168     XBT_LOG_NEW_CATEGORY(cname,desc);                   \
169     XBT_LOG_DEFAULT_CATEGORY(cname)     
170 #endif
171
172
173
174 /**
175  * \ingroup XBT_log  
176  * \param cname name of the cat
177  * \param parent name of the parent
178  * \param desc string describing the purpose of this category
179  * \hideinitializer
180  *
181  * Creates a new subcategory of the parent category and makes it the default
182  * (used by macros that don't explicitly specify a category).
183  */
184 #define XBT_LOG_NEW_DEFAULT_SUBCATEGORY(cname, parent, desc) \
185     XBT_LOG_NEW_SUBCATEGORY(cname, parent, desc);            \
186     XBT_LOG_DEFAULT_CATEGORY(cname)
187
188 /**
189  * \ingroup XBT_log  
190  * \param cname name of the cat
191  * \hideinitializer
192  *
193  * Indicates that a category you'll use in this file (to get subcategories of it, 
194  * for example) really lives in another file.
195  */
196
197 #define XBT_LOG_EXTERNAL_CATEGORY(cname) \
198    extern s_xbt_log_category_t _XBT_LOGV(cname)
199
200 /**
201  * \ingroup XBT_log
202  * \param cname name of the cat
203  * \hideinitializer
204  *
205  * Indicates that the default category of this file was declared in another file.
206  */
207
208 #define XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(cname) \
209    XBT_LOG_EXTERNAL_CATEGORY(cname);\
210    XBT_LOG_DEFAULT_CATEGORY(cname)
211
212 /* Functions you may call */
213
214 XBT_PUBLIC(void) xbt_log_control_set(const char* cs);
215
216 /* Forward declarations */
217 typedef struct xbt_log_appender_s s_xbt_log_appender_t,*xbt_log_appender_t;
218 typedef struct xbt_log_event_s    s_xbt_log_event_t,   *xbt_log_event_t;
219 typedef struct xbt_log_category_s s_xbt_log_category_t,*xbt_log_category_t;
220
221 /*
222  * Do NOT access any members of this structure directly. FIXME: move to private?
223  */
224 struct xbt_log_category_s {
225             xbt_log_category_t parent;
226 /*@null@*/  xbt_log_category_t firstChild; 
227 /*@null@*/  xbt_log_category_t nextSibling;
228             const char *name;
229             int threshold;
230             int isThreshInherited;
231 /*@null@*/  xbt_log_appender_t appender;
232                         int willLogToParent;
233   /* TODO: Formats? */
234 };
235
236 struct xbt_log_appender_s {
237   void (*do_append) (xbt_log_appender_t thisLogAppender,
238                     xbt_log_event_t event, const char *fmt);
239   void *appender_data;
240 };
241
242 struct xbt_log_event_s {
243   xbt_log_category_t cat;
244   e_xbt_log_priority_t priority;
245   const char* fileName;
246   const char* functionName;
247   int lineNum;
248   va_list ap;
249 };
250
251 /**
252  * \ingroup XBT_log_implem
253  * \param cat the category (not only its name, but the variable)
254  * \param thresholdPriority the priority
255  *
256  * Programatically alters a category's threshold priority (don't use).
257  */
258 XBT_PUBLIC(void) xbt_log_threshold_set(xbt_log_category_t cat,
259                                    e_xbt_log_priority_t thresholdPriority);
260
261 /**
262  * \ingroup XBT_log_implem  
263  * \param cat the category (not only its name, but the variable)
264  * \param parent the parent cat
265  *
266  * Programatically alter a category's parent (don't use).
267  */
268 XBT_PUBLIC(void) xbt_log_parent_set(xbt_log_category_t cat,
269                                 xbt_log_category_t parent);
270
271 /**
272  * \ingroup XBT_log_implem  
273  * \param cat the category (not only its name, but the variable)
274  * \param app the appender
275  *
276  * Programatically sets the category's appender (don't use).
277  */
278 XBT_PUBLIC(void) xbt_log_appender_set(xbt_log_category_t cat,
279                                   xbt_log_appender_t app);
280
281 /* Functions that you shouldn't call. */
282 XBT_PUBLIC(void) _xbt_log_event_log(xbt_log_event_t ev,
283                                 const char *fmt,
284                                 ...) _XBT_GNUC_PRINTF(2,3);
285
286 XBT_PUBLIC(int) _xbt_log_cat_init(e_xbt_log_priority_t priority, 
287                               xbt_log_category_t   category);
288
289
290 extern XBT_IMPORT_NO_PUBLIC(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT);
291
292 XBT_LOG_EXTERNAL_CATEGORY(GRAS);
293
294 extern xbt_log_appender_t xbt_log_default_appender;
295
296 /**
297  * \ingroup XBT_log 
298  * \param catName name of the category
299  * \param priority minimal priority to be enabled to return true
300  * \hideinitializer
301  *
302  * Returns true if the given priority is enabled for the category.
303  * If you have expensive expressions that are computed outside of the log
304  * command and used only within it, you should make its evaluation conditional
305  * using this macro.
306  */
307 #define XBT_LOG_ISENABLED(catName, priority) \
308             _XBT_LOG_ISENABLEDV(_XBT_LOGV(catName), priority)
309
310 /*
311  * Helper function that implements XBT_LOG_ISENABLED.
312  *
313  * NOTES
314  * First part is a compile-time constant.
315  * Call to _log_initCat only happens once.
316  */
317 #define _XBT_LOG_ISENABLEDV(catv, priority)                  \
318        (priority >= XBT_LOG_STATIC_THRESHOLD                 \
319         && priority >= catv.threshold                         \
320         && (catv.threshold != xbt_log_priority_uninitialized \
321             || _xbt_log_cat_init(priority, &catv)) )
322
323 /*
324  * Internal Macros
325  * Some kludge macros to ease maintenance. See how they're used below.
326  *
327  * IMPLEMENTATION NOTE: To reduce the parameter passing overhead of an enabled
328  * message, the many parameters passed to the logging function are packed in a
329  * structure. Since these values will be usually be passed to at least 3
330  * functions, this is a win.
331  * It also allows adding new values (such as a timestamp) without breaking
332  * code. 
333  * Setting the LogEvent's valist member is done inside _log_logEvent.
334  */
335
336 #define _XBT_LOG_PRE(catv, priority) do {                        \
337      if (_XBT_LOG_ISENABLEDV(catv, priority)) {                  \
338          s_xbt_log_event_t _log_ev =                             \
339              {NULL,priority,__FILE__,_XBT_FUNCTION,__LINE__};    \
340                 _log_ev.cat = &(catv);                           \
341               _xbt_log_event_log(&_log_ev                        \
342               
343
344 #define _XBT_LOG_POST                          \
345                         );                      \
346      } } while(0)
347
348
349 /* Logging Macros */
350
351 #ifdef XBT_LOG_MAYDAY
352 # define CLOG0(c, p, f)                   fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__)
353 # define CLOG1(c, p, f,a1)                fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1)               
354 # define CLOG2(c, p, f,a1,a2)             fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2)            
355 # define CLOG3(c, p, f,a1,a2,a3)          fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3)         
356 # define CLOG4(c, p, f,a1,a2,a3,a4)       fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4)      
357 # define CLOG5(c, p, f,a1,a2,a3,a4,a5)    fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5)   
358 # define CLOG6(c, p, f,a1,a2,a3,a4,a5,a6) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6)
359 # define CLOG7(c, p, f,a1,a2,a3,a4,a5,a6,a7) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7)
360 # define CLOG8(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8)
361 # define CLOG9(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9)
362 # define CLOG10(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
363 #else
364 # define CLOG0(c, p, f)                   _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f _XBT_LOG_POST            
365 # define CLOG1(c, p, f,a1)                _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1 _XBT_LOG_POST                 
366 # define CLOG2(c, p, f,a1,a2)             _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2 _XBT_LOG_POST
367 # define CLOG3(c, p, f,a1,a2,a3)          _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3 _XBT_LOG_POST
368 # define CLOG4(c, p, f,a1,a2,a3,a4)       _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4 _XBT_LOG_POST
369 # define CLOG5(c, p, f,a1,a2,a3,a4,a5)    _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5 _XBT_LOG_POST
370 # define CLOG6(c, p, f,a1,a2,a3,a4,a5,a6) _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6 _XBT_LOG_POST
371 # define CLOG7(c, p, f,a1,a2,a3,a4,a5,a6,a7) _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7 _XBT_LOG_POST
372 # define CLOG8(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8) _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8 _XBT_LOG_POST
373 # define CLOG9(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9) _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8,a9 _XBT_LOG_POST
374 # define CLOG10(c, p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) _XBT_LOG_PRE(_XBT_LOGV(c),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10 _XBT_LOG_POST
375 #endif
376 #define CDEBUG0(c, f)                   CLOG0(c, xbt_log_priority_debug, f)
377 #define CDEBUG1(c, f,a1)                CLOG1(c, xbt_log_priority_debug, f,a1)
378 #define CDEBUG2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_debug, f,a1,a2)
379 #define CDEBUG3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_debug, f,a1,a2,a3)
380 #define CDEBUG4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_debug, f,a1,a2,a3,a4)
381 #define CDEBUG5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5)
382 #define CDEBUG6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6)
383 #define CDEBUG7(c, f,a1,a2,a3,a4,a5,a6,a7) CLOG7(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7)
384 #define CDEBUG8(c, f,a1,a2,a3,a4,a5,a6,a7,a8) CLOG8(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8)
385 #define CDEBUG9(c, f,a1,a2,a3,a4,a5,a6,a7,a8,a9) CLOG9(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8,a9)
386 /** @ingroup XBT_log
387  *  @hideinitializer
388  * \param c the category on which to log
389  * \param f the format string
390  * \param a1 first argument of the format
391  * \param a2 second argument of the format
392  * \param a3 third argument of the format
393  * \param a4 fourth argument of the format
394  * \param a5 fifth argument of the format
395  * \param a6 sixth argument of the format
396  * \param a7 seventh argument of the format
397  * \param a8 eighth argument of the format
398  * \param a9 ninth argument of the format
399  * \param a10 tenth argument of the format
400  *  @brief Log an event at the DEBUG priority on the specified category with these args (CDEBUGn exists for any n<10).
401  */
402 #define CDEBUG10(c, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) CLOG10(c, xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
403
404 #define CVERB0(c, f)                   CLOG0(c, xbt_log_priority_verbose, f)
405 #define CVERB1(c, f,a1)                CLOG1(c, xbt_log_priority_verbose, f,a1)
406 #define CVERB2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_verbose, f,a1,a2)
407 #define CVERB3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_verbose, f,a1,a2,a3)
408 #define CVERB4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_verbose, f,a1,a2,a3,a4)
409 #define CVERB5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_verbose, f,a1,a2,a3,a4,a5)
410 /** @ingroup XBT_log
411  *  @hideinitializer
412  *  @brief Log an event at the VERB priority on the specified category with these args (CVERBn exists for any n<6).
413  */
414 #define CVERB6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_verbose, f,a1,a2,a3,a4,a5,a6)
415
416 #define CINFO0(c, f)                   CLOG0(c, xbt_log_priority_info, f)
417 #define CINFO1(c, f,a1)                CLOG1(c, xbt_log_priority_info, f,a1)
418 #define CINFO2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_info, f,a1,a2)
419 #define CINFO3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_info, f,a1,a2,a3)
420 #define CINFO4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_info, f,a1,a2,a3,a4)
421 #define CINFO5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_info, f,a1,a2,a3,a4,a5)
422 #define CINFO6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6)
423 #define CINFO7(c, f,a1,a2,a3,a4,a5,a6,a7) CLOG7(c, xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6,a7)
424 /** @ingroup XBT_log
425  *  @hideinitializer
426  *  @brief Log an event at the INFO priority on the specified category with these args (CINFOn exists for any n<8).
427  */
428 #define CINFO8(c, f,a1,a2,a3,a4,a5,a6,a7,a8) CLOG8(c, xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6,a7,a8)
429
430 #define CWARN0(c, f)                   CLOG0(c, xbt_log_priority_warning, f)
431 #define CWARN1(c, f,a1)                CLOG1(c, xbt_log_priority_warning, f,a1)
432 #define CWARN2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_warning, f,a1,a2)
433 #define CWARN3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_warning, f,a1,a2,a3)
434 #define CWARN4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_warning, f,a1,a2,a3,a4)
435 #define CWARN5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_warning, f,a1,a2,a3,a4,a5)
436 /** @ingroup XBT_log
437  *  @hideinitializer
438  *  @brief Log an event at the WARN priority on the specified category with these args (CWARNn exists for any n<6).
439  */
440 #define CWARN6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
441
442 #define CERROR0(c, f)                   CLOG0(c, xbt_log_priority_error, f)
443 #define CERROR1(c, f,a1)                CLOG1(c, xbt_log_priority_error, f,a1)
444 #define CERROR2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_error, f,a1,a2)
445 #define CERROR3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_error, f,a1,a2,a3)
446 #define CERROR4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_error, f,a1,a2,a3,a4)
447 #define CERROR5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_error, f,a1,a2,a3,a4,a5)
448 /** @ingroup XBT_log
449  *  @hideinitializer
450  *  @brief Log an event at the ERROR priority on the specified category with these args (CERRORn exists for any n<6).
451  */
452 #define CERROR6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_error, f,a1,a2,a3,a4,a5,a6)
453
454 #define CCRITICAL0(c, f)                   CLOG0(c, xbt_log_priority_critical, f)
455 #define CCRITICAL1(c, f,a1)                CLOG1(c, xbt_log_priority_critical, f,a1)
456 #define CCRITICAL2(c, f,a1,a2)             CLOG2(c, xbt_log_priority_critical, f,a1,a2)
457 #define CCRITICAL3(c, f,a1,a2,a3)          CLOG3(c, xbt_log_priority_critical, f,a1,a2,a3)
458 #define CCRITICAL4(c, f,a1,a2,a3,a4)       CLOG4(c, xbt_log_priority_critical, f,a1,a2,a3,a4)
459 #define CCRITICAL5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, xbt_log_priority_critical, f,a1,a2,a3,a4,a5)
460 /** @ingroup XBT_log
461  *  @hideinitializer
462  *  @brief Log an event at the CRITICAL priority on the specified category with these args (CCRITICALn exists for any n<6).
463  */
464 #define CCRITICAL6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, xbt_log_priority_critical, f,a1,a2,a3,a4,a5,a6)
465
466 #ifdef XBT_LOG_MAYDAY
467 # define LOG0(p, f)                   fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__)
468 # define LOG1(p, f,a1)                fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1)               
469 # define LOG2(p, f,a1,a2)             fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2)            
470 # define LOG3(p, f,a1,a2,a3)          fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3)         
471 # define LOG4(p, f,a1,a2,a3,a4)       fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4)      
472 # define LOG5(p, f,a1,a2,a3,a4,a5)    fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5)   
473 # define LOG6(p, f,a1,a2,a3,a4,a5,a6) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6)
474 # define LOG7(p, f,a1,a2,a3,a4,a5,a6,a7) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7)
475 # define LOG8(p, f,a1,a2,a3,a4,a5,a6,a7,a8) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8)
476 # define LOG9(p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9)
477 # define LOG10(p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) fprintf(stderr,"%s:%d:" f "\n",__FILE__,__LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
478 #else
479 # define LOG0(p, f)                   _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f _XBT_LOG_POST
480 # define LOG1(p, f,a1)                _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1 _XBT_LOG_POST
481 # define LOG2(p, f,a1,a2)             _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2 _XBT_LOG_POST
482 # define LOG3(p, f,a1,a2,a3)          _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3 _XBT_LOG_POST
483 # define LOG4(p, f,a1,a2,a3,a4)       _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4 _XBT_LOG_POST
484 # define LOG5(p, f,a1,a2,a3,a4,a5)    _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5 _XBT_LOG_POST
485 # define LOG6(p, f,a1,a2,a3,a4,a5,a6) _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6 _XBT_LOG_POST
486 # define LOG7(p, f,a1,a2,a3,a4,a5,a6,a7) _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7 _XBT_LOG_POST
487 # define LOG8(p, f,a1,a2,a3,a4,a5,a6,a7,a8) _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8 _XBT_LOG_POST
488 # define LOG9(p, f,a1,a2,a3,a4,a5,a6,a7,a8,a9) _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8,a9 _XBT_LOG_POST
489 # define LOG10(p,f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) _XBT_LOG_PRE((*_XBT_LOGV(default)),p) ,f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10 _XBT_LOG_POST
490 #endif
491
492 #define DEBUG0(f)                   LOG0(xbt_log_priority_debug, f)
493 #define DEBUG1(f,a1)                LOG1(xbt_log_priority_debug, f,a1)
494 #define DEBUG2(f,a1,a2)             LOG2(xbt_log_priority_debug, f,a1,a2)
495 #define DEBUG3(f,a1,a2,a3)          LOG3(xbt_log_priority_debug, f,a1,a2,a3)
496 #define DEBUG4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_debug, f,a1,a2,a3,a4)
497 #define DEBUG5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_debug, f,a1,a2,a3,a4,a5)
498 #define DEBUG6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6)
499 #define DEBUG7(f,a1,a2,a3,a4,a5,a6,a7) LOG7(xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7)
500 #define DEBUG8(f,a1,a2,a3,a4,a5,a6,a7,a8) LOG8(xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8)
501 #define DEBUG9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) LOG9(xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8,a9)
502 /** @ingroup XBT_log
503  *  @hideinitializer
504  * \param f the format string
505  * \param a1 first argument of the format
506  * \param a2 second argument of the format
507  * \param a3 third argument of the format
508  * \param a4 fourth argument of the format
509  * \param a5 fifth argument of the format
510  * \param a6 sixth argument of the format
511  * \param a7 seventh argument of the format
512  * \param a8 eighth argument of the format
513  * \param a9 ninth argument of the format
514  * \param a10 tenth argument of the format
515  *  @brief Log an event at the DEBUG priority on the default category with these args (DEBUGn exists for any n<10)
516  */
517 #define DEBUG10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) LOG10(xbt_log_priority_debug, f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
518
519 #define VERB0(f)                   LOG0(xbt_log_priority_verbose, f)
520 #define VERB1(f,a1)                LOG1(xbt_log_priority_verbose, f,a1)
521 #define VERB2(f,a1,a2)             LOG2(xbt_log_priority_verbose, f,a1,a2)
522 #define VERB3(f,a1,a2,a3)          LOG3(xbt_log_priority_verbose, f,a1,a2,a3)
523 #define VERB4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_verbose, f,a1,a2,a3,a4)
524 #define VERB5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_verbose, f,a1,a2,a3,a4,a5)
525 /** @ingroup XBT_log
526  *  @hideinitializer
527  *  @brief Log an event at the VERB priority on the default category with these args (VERBn exists for any n<6).
528  */
529 #define VERB6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_verbose, f,a1,a2,a3,a4,a5,a6)
530
531 #define INFO0(f)                   LOG0(xbt_log_priority_info, f)
532 #define INFO1(f,a1)                LOG1(xbt_log_priority_info, f,a1)
533 #define INFO2(f,a1,a2)             LOG2(xbt_log_priority_info, f,a1,a2)
534 #define INFO3(f,a1,a2,a3)          LOG3(xbt_log_priority_info, f,a1,a2,a3)
535 #define INFO4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_info, f,a1,a2,a3,a4)
536 #define INFO5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_info, f,a1,a2,a3,a4,a5)
537 #define INFO6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6)
538 #define INFO7(f,a1,a2,a3,a4,a5,a6,a7) LOG7(xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6,a7)
539 /** @ingroup XBT_log
540  *  @hideinitializer
541  *  @brief Log an event at the INFO priority on the default category with these args (INFOn exists for any n<8).
542  */
543 #define INFO8(f,a1,a2,a3,a4,a5,a6,a7,a8) LOG8(xbt_log_priority_info, f,a1,a2,a3,a4,a5,a6,a7,a8)
544
545 #define WARN0(f)                   LOG0(xbt_log_priority_warning, f)
546 #define WARN1(f,a1)                LOG1(xbt_log_priority_warning, f,a1)
547 #define WARN2(f,a1,a2)             LOG2(xbt_log_priority_warning, f,a1,a2)
548 #define WARN3(f,a1,a2,a3)          LOG3(xbt_log_priority_warning, f,a1,a2,a3)
549 #define WARN4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_warning, f,a1,a2,a3,a4)
550 #define WARN5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_warning, f,a1,a2,a3,a4,a5)
551 /** @ingroup XBT_log
552  *  @hideinitializer
553  *  @brief Log an event at the WARN priority on the default category with these args (WARNn exists for any n<6).
554  */
555 #define WARN6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
556
557 #define ERROR0(f)                   LOG0(xbt_log_priority_error, f)
558 #define ERROR1(f,a1)                LOG1(xbt_log_priority_error, f,a1)
559 #define ERROR2(f,a1,a2)             LOG2(xbt_log_priority_error, f,a1,a2)
560 #define ERROR3(f,a1,a2,a3)          LOG3(xbt_log_priority_error, f,a1,a2,a3)
561 #define ERROR4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_error, f,a1,a2,a3,a4)
562 #define ERROR5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_error, f,a1,a2,a3,a4,a5)
563 /** @ingroup XBT_log
564  *  @hideinitializer
565  *  @brief Log an event at the ERROR priority on the default category with these args (ERRORn exists for any n<6).
566  */
567 #define ERROR6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_error, f,a1,a2,a3,a4,a5,a6)
568
569 #define CRITICAL0(f)                   LOG0(xbt_log_priority_critical, f)
570 #define CRITICAL1(f,a1)                LOG1(xbt_log_priority_critical, f,a1)
571 #define CRITICAL2(f,a1,a2)             LOG2(xbt_log_priority_critical, f,a1,a2)
572 #define CRITICAL3(f,a1,a2,a3)          LOG3(xbt_log_priority_critical, f,a1,a2,a3)
573 #define CRITICAL4(f,a1,a2,a3,a4)       LOG4(xbt_log_priority_critical, f,a1,a2,a3,a4)
574 #define CRITICAL5(f,a1,a2,a3,a4,a5)    LOG5(xbt_log_priority_critical, f,a1,a2,a3,a4,a5)
575 /** @ingroup XBT_log
576  *  @hideinitializer
577  *  @brief Log an event at the CRITICAL priority on the default category with these args (CRITICALn exists for any n<6).
578  */
579 #define CRITICAL6(f,a1,a2,a3,a4,a5,a6) LOG6(xbt_log_priority_critical, f,a1,a2,a3,a4,a5,a6)
580
581 /** @ingroup XBT_log
582  *  @hideinitializer
583  *  @brief Log at TRACE priority that we entered in current function.
584  */
585 #define XBT_IN               LOG1(xbt_log_priority_trace, ">> begin of %s",     _XBT_FUNCTION)
586 #define XBT_IN1(fmt,a)       LOG2(xbt_log_priority_trace, ">> begin of %s" fmt, _XBT_FUNCTION, a)
587 #define XBT_IN2(fmt,a,b)     LOG3(xbt_log_priority_trace, ">> begin of %s" fmt, _XBT_FUNCTION, a,b)
588 #define XBT_IN3(fmt,a,b,c)   LOG4(xbt_log_priority_trace, ">> begin of %s" fmt, _XBT_FUNCTION, a,b,c)
589 #define XBT_IN4(fmt,a,b,c,d) LOG5(xbt_log_priority_trace, ">> begin of %s" fmt, _XBT_FUNCTION, a,b,c,d)
590 /** @ingroup XBT_log
591  *  @hideinitializer
592  *  @brief Log at TRACE priority that we entered in current function, appending a user specified format taking 5 args (XBT_INn exists for all n in [1,6])
593  */
594 #define XBT_IN5(fmt,a,b,c,d,e) LOG6(xbt_log_priority_trace, ">> begin of %s" fmt, _XBT_FUNCTION, a,b,c,d,e)
595 /** @ingroup XBT_log
596  *  @hideinitializer
597  *  @brief Log at TRACE priority that we exited the current function.
598  */
599 #define XBT_OUT              LOG1(xbt_log_priority_trace, "<< end of %s",       _XBT_FUNCTION)
600 /** @ingroup XBT_log
601  *  @hideinitializer
602  *  @brief Log at TRACE priority a message indicating that we reached that point.
603  */
604 #define XBT_HERE             LOG0(xbt_log_priority_trace, "-- was here")
605
606
607 SG_END_DECL()
608
609 #endif /* ! _XBT_LOG_H_ */