X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/35471ecdf533b2701ca99d3921c42944531883ce..a76358453a876eb6ed6965bb63735a855df9f737:/src/xbt/log.c diff --git a/src/xbt/log.c b/src/xbt/log.c index c5d387a536..6e02d5354b 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -12,7 +12,8 @@ #include #include /* snprintf */ #include /* snprintf */ -#include "gras_config.h" /* to get a working stdarg.h */ + +#include "portable.h" /* to get a working stdarg.h */ #include "xbt_modinter.h" @@ -46,6 +47,7 @@ - \ref log_internals - \ref log_in_perf - \ref log_in_app + - \ref XBT_log_cats \section log_overview 1. Introduction @@ -124,13 +126,13 @@ the category's parent. A category is created by a macro call at the top level of a file. A category can be created with any one of the following macros: - - \ref XBT_LOG_NEW_CATEGORY(MyCat); Create a new root - - \ref XBT_LOG_NEW_SUBCATEGORY(MyCat, ParentCat); + - \ref XBT_LOG_NEW_CATEGORY(MyCat,desc); Create a new root + - \ref XBT_LOG_NEW_SUBCATEGORY(MyCat, ParentCat,desc); Create a new category being child of the category ParentCat - - \ref XBT_LOG_NEW_DEFAULT_CATEGORY(MyCat); + - \ref XBT_LOG_NEW_DEFAULT_CATEGORY(MyCat,desc); Like XBT_LOG_NEW_CATEGORY, but the new category is the default one in this file - - \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY(MyCat, ParentCat); + - \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY(MyCat, ParentCat,desc); Like XBT_LOG_NEW_SUBCATEGORY, but the new category is the default one in this file @@ -202,17 +204,28 @@ First of all, each module should register its own category into the categories tree using \ref XBT_LOG_NEW_DEFAULT_SUBCATEGORY. Then, logging should be done with the DEBUG, VERB, INFO, WARN, -ERROR or CRITICAL macro families. For each group, there is 6 different -macros (like DEBUG0, DEBUG1, DEBUG2, DEBUG3, DEBUG4 and DEBUG5), only differing -in the number of arguments passed along the format. This is because we want -SimGrid itself to keep compilable on ancient compiler not supporting variable -number of arguments to macros. But we should provide a macro simpler to use for -the users not interested in SP3 machines (FIXME). - +ERROR or CRITICAL macro families (such as #DEBUG10, #VERB6, +#INFO8, #WARN6, #ERROR6 and #CRITICAL6). For each group, there is at +least 6 different macros (like DEBUG0, DEBUG1, DEBUG2, DEBUG3, DEBUG4 and +DEBUG5), only differing in the number of arguments passed along the format. +This is because we want SimGrid itself to keep compilable on ancient +compiler not supporting variable number of arguments to macros. But we +should provide a macro simpler to use for the users not interested in SP3 +machines (FIXME). + Under GCC, these macro check there arguments the same way than printf does. So, if you compile with -Wall, the folliwing code will issue a warning: DEBUG2("Found %s (id %f)", some_string, a_double) +If you want to specify the category to log onto (for example because you +have more than one category per file, add a C before the name of the log +producing macro (ie, use #CDEBUG10, #CVERB6, #CINFO8, #CWARN6, #CERROR6 and +#CCRITICAL6 and friends), and pass the category name as first argument. + +The TRACE priority is not used the same way than the other. You should use +the #XBT_IN, XBT_IN (up to #XBT_IN5), #XBT_OUT and #XBT_HERE macros +instead. + \section log_API_example 2.5 Example of use Here is a more complete example: @@ -398,6 +411,7 @@ static void _apply_control(xbt_log_category_t cat) { int cursor; xbt_log_setting_t setting=NULL; int found = 0; + s_xbt_log_event_t _log_ev; if (!xbt_log_settings) return; @@ -415,19 +429,28 @@ static void _apply_control(xbt_log_category_t cat) { xbt_log_threshold_set(cat, setting->thresh); xbt_dynar_cursor_rm(xbt_log_settings,&cursor); + if (cat->threshold <= xbt_log_priority_debug) { - s_xbt_log_event_t _log_ev = - {cat,xbt_log_priority_debug,__FILE__,_XBT_FUNCTION,__LINE__}; + _log_ev.cat = cat; + _log_ev.priority = xbt_log_priority_debug; + _log_ev.fileName = __FILE__ ; + _log_ev.functionName = _XBT_FUNCTION ; + _log_ev.lineNum = __LINE__ ; + _xbt_log_event_log(&_log_ev, "Apply settings for category '%s': set threshold to %s (=%d)", - cat->name, + cat->name, xbt_log_priority_names[cat->threshold], cat->threshold); } } } if (!found && cat->threshold <= xbt_log_priority_verbose) { - s_xbt_log_event_t _log_ev = - {cat,xbt_log_priority_verbose,__FILE__,_XBT_FUNCTION,__LINE__}; + _log_ev.cat = cat; + _log_ev.priority = xbt_log_priority_verbose; + _log_ev.fileName = __FILE__ ; + _log_ev.functionName = _XBT_FUNCTION ; + _log_ev.lineNum = __LINE__ ; + _xbt_log_event_log(&_log_ev, "Category '%s': inherited threshold = %s (=%d)", cat->name, @@ -546,7 +569,7 @@ static void _xbt_log_parse_setting(const char* control_string, xbt_assert1(*dot == '.' && *eq == '=', "Invalid control string '%s'",control_string); - if (!strncmp(dot + 1, "thresh", min(eq - dot - 1,strlen("thresh")))) { + if (!strncmp(dot + 1, "thresh", min((size_t)(eq - dot - 1),strlen("thresh")))) { int i; char *neweq=xbt_strdup(eq+1); char *p=neweq-1; @@ -558,14 +581,14 @@ static void _xbt_log_parse_setting(const char* control_string, } DEBUG1("New priority name = %s",neweq); - for (i=0; ithresh=i; + if (ithresh= (e_xbt_log_priority_t) i; } else { xbt_assert1(FALSE,"Unknown priority name: %s",eq+1); } @@ -672,7 +695,7 @@ void xbt_log_control_set(const char* control_string) { p=strrchr(cs,' '); if (p) { *p='\0'; - *p++; + p++; } else { p=cs; done = 1;