X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2fd15b45d25da87fc9c2ae646c7ff50cc303dfb1..889f0aaaa5ef72d1de31d247cd703a1c04b7821f:/src/xbt/log.c diff --git a/src/xbt/log.c b/src/xbt/log.c index 6592d41e0e..d0577f8f86 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -11,7 +11,7 @@ #include /* snprintf */ #include /* snprintf */ -#include "src/portable.h" /* to get a working stdarg.h */ +#include "src/internal_config.h" #include "src/xbt_modinter.h" @@ -24,7 +24,7 @@ #include "xbt/xbt_os_thread.h" int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */ -static xbt_os_rmutex_t log_cat_init_mutex = NULL; +static xbt_os_mutex_t log_cat_init_mutex = NULL; /** \addtogroup XBT_log * @@ -359,7 +359,6 @@ Here are the existing format directives: - %%l: location where the log event was raised (LOG4J compatible, like '%%F:%%L' -- this is a l as in 'l'etter) - %%L: line number where the log event was raised (LOG4J compatible) - %%M: function name (LOG4J compatible -- called method name here of course). - Defined only when using gcc because there is no __FUNCTION__ elsewhere. - %%b: full backtrace (Called %%throwable in LOG4J). Defined only under windows or when using the GNU libc because backtrace() is not defined @@ -477,8 +476,7 @@ Each category has an optional appender. An appender is a pointer to a structure which starts with a pointer to a do_append() function. do_append() prints a message to a log. -When a category is passed a message by one of the logging macros, the -category performs the following actions: +When a category is passed a message by one of the logging macros, the category performs the following actions: - if the category has an appender, the message is passed to the appender's do_append() function, @@ -518,8 +516,7 @@ static void _free_setting(void *s) } } -static void _xbt_log_cat_apply_set(xbt_log_category_t category, - xbt_log_setting_t setting); +static void _xbt_log_cat_apply_set(xbt_log_category_t category, xbt_log_setting_t setting); const char *xbt_log_priority_names[8] = { "NONE", @@ -541,8 +538,7 @@ s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = { 0 /* additivity */ }; -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, - "Loggings from the logging mechanism itself"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism itself"); /* create the default appender and install it in the root category, which were already created (damnit. Too slow little beetle) */ @@ -552,7 +548,7 @@ void xbt_log_preinit(void) xbt_log_default_layout = xbt_log_layout_simple_new(NULL); _XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender; _XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout; - log_cat_init_mutex = xbt_os_rmutex_init(); + log_cat_init_mutex = xbt_os_mutex_init(); } static void xbt_log_connect_categories(void) @@ -562,7 +558,6 @@ static void xbt_log_connect_categories(void) /* xbt */ XBT_LOG_CONNECT(xbt); - XBT_LOG_CONNECT(graphxml_parse); XBT_LOG_CONNECT(log); XBT_LOG_CONNECT(module); XBT_LOG_CONNECT(replay); @@ -571,9 +566,6 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(xbt_dict); XBT_LOG_CONNECT(xbt_dict_cursor); XBT_LOG_CONNECT(xbt_dict_elm); -#ifdef XBT_USE_DEPRECATED - XBT_LOG_CONNECT(xbt_dict_multi); -#endif XBT_LOG_CONNECT(xbt_dyn); XBT_LOG_CONNECT(xbt_ex); XBT_LOG_CONNECT(xbt_fifo); @@ -590,8 +582,7 @@ static void xbt_log_connect_categories(void) /* The following categories are only defined in libsimgrid */ /* bindings */ -#ifdef HAVE_LUA - XBT_LOG_CONNECT(bindings); +#if HAVE_LUA XBT_LOG_CONNECT(lua); XBT_LOG_CONNECT(lua_host); XBT_LOG_CONNECT(lua_platf); @@ -617,14 +608,14 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(instr_TI_trace); /* jedule */ -#ifdef HAVE_JEDULE +#if HAVE_JEDULE XBT_LOG_CONNECT(jedule); XBT_LOG_CONNECT(jed_out); XBT_LOG_CONNECT(jed_sd); #endif /* mc */ -#ifdef HAVE_MC +#if HAVE_MC XBT_LOG_CONNECT(mc); XBT_LOG_CONNECT(mc_checkpoint); XBT_LOG_CONNECT(mc_comm_determinism); @@ -632,13 +623,12 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(mc_diff); XBT_LOG_CONNECT(mc_dwarf); XBT_LOG_CONNECT(mc_hash); - XBT_LOG_CONNECT(mc_ignore); XBT_LOG_CONNECT(mc_liveness); XBT_LOG_CONNECT(mc_memory); XBT_LOG_CONNECT(mc_page_snapshot); XBT_LOG_CONNECT(mc_request); XBT_LOG_CONNECT(mc_safety); - XBT_LOG_CONNECT(mc_visited); + XBT_LOG_CONNECT(mc_VisitedState); XBT_LOG_CONNECT(mc_client); XBT_LOG_CONNECT(mc_client_api); XBT_LOG_CONNECT(mc_comm_pattern); @@ -670,7 +660,7 @@ static void xbt_log_connect_categories(void) /* simdag */ XBT_LOG_CONNECT(sd); XBT_LOG_CONNECT(sd_daxparse); -#ifdef HAVE_GRAPHVIZ +#if HAVE_GRAPHVIZ XBT_LOG_CONNECT(sd_dotparse); #endif XBT_LOG_CONNECT(sd_kernel); @@ -695,8 +685,6 @@ static void xbt_log_connect_categories(void) /* surf */ XBT_LOG_CONNECT(surf); - XBT_LOG_CONNECT(platf_generator); - XBT_LOG_CONNECT(random); XBT_LOG_CONNECT(surf_config); XBT_LOG_CONNECT(surf_cpu); XBT_LOG_CONNECT(surf_cpu_cas); @@ -707,7 +695,7 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(surf_lagrange_dichotomy); XBT_LOG_CONNECT(surf_maxmin); XBT_LOG_CONNECT(surf_network); -#ifdef HAVE_NS3 +#if HAVE_NS3 XBT_LOG_CONNECT(ns3); #endif XBT_LOG_CONNECT(surf_parse); @@ -797,7 +785,7 @@ static void log_cat_exit(xbt_log_category_t cat) void xbt_log_postexit(void) { XBT_VERB("Exiting log"); - xbt_os_rmutex_destroy(log_cat_init_mutex); + xbt_os_mutex_destroy(log_cat_init_mutex); xbt_dynar_free(&xbt_log_settings); log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT)); } @@ -812,10 +800,8 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) { xbt_log_category_t cat = ev->cat; - xbt_assert(ev->priority >= 0, - "Negative logging priority naturally forbidden"); - xbt_assert(ev->priority < sizeof(xbt_log_priority_names), - "Priority %d is greater than the biggest allowed value", + xbt_assert(ev->priority >= 0, "Negative logging priority naturally forbidden"); + xbt_assert(ev->priority < sizeof(xbt_log_priority_names), "Priority %d is greater than the biggest allowed value", ev->priority); do { @@ -824,8 +810,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) if (!appender) continue; /* No appender, try next */ - xbt_assert(cat->layout, - "No valid layout for the appender of category %s", cat->name); + xbt_assert(cat->layout, "No valid layout for the appender of category %s", cat->name); /* First, try with a static buffer */ if (XBT_LOG_STATIC_BUFFER_SIZE) { @@ -866,18 +851,15 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) /* NOTE: * - * The standard logging macros use _XBT_LOG_ISENABLED, which calls - * _xbt_log_cat_init(). Thus, if we want to avoid an infinite - * recursion, we can not use the standard logging macros in - * _xbt_log_cat_init(), and in all functions called from it. + * The standard logging macros use _XBT_LOG_ISENABLED, which calls _xbt_log_cat_init(). Thus, if we want to avoid an + * infinite recursion, we can not use the standard logging macros in _xbt_log_cat_init(), and in all functions called + * from it. * - * To circumvent the problem, we define the macro_xbt_log_init() as - * (0) for the length of the affected functions, and we do not forget - * to undefine it at the end! + * To circumvent the problem, we define the macro_xbt_log_init() as (0) for the length of the affected functions, and + * we do not forget to undefine it at the end! */ -static void _xbt_log_cat_apply_set(xbt_log_category_t category, - xbt_log_setting_t setting) +static void _xbt_log_cat_apply_set(xbt_log_category_t category, xbt_log_setting_t setting) { #define _xbt_log_cat_init(a, b) (0) @@ -885,15 +867,13 @@ static void _xbt_log_cat_apply_set(xbt_log_category_t category, xbt_log_threshold_set(category, setting->thresh); XBT_DEBUG("Apply settings for category '%s': set threshold to %s (=%d)", - category->name, xbt_log_priority_names[category->threshold], - category->threshold); + category->name, xbt_log_priority_names[category->threshold], category->threshold); } if (setting->fmt) { xbt_log_layout_set(category, xbt_log_layout_format_new(setting->fmt)); - XBT_DEBUG("Apply settings for category '%s': set format to %s", - category->name, setting->fmt); + XBT_DEBUG("Apply settings for category '%s': set format to %s", category->name, setting->fmt); } if (setting->additivity != -1) { @@ -907,30 +887,25 @@ static void _xbt_log_cat_apply_set(xbt_log_category_t category, if (!category->layout) xbt_log_layout_set(category, xbt_log_layout_simple_new(NULL)); category->additivity = 0; - XBT_DEBUG("Set %p as appender of category '%s'", - setting->appender, category->name); + XBT_DEBUG("Set %p as appender of category '%s'", setting->appender, category->name); } #undef _xbt_log_cat_init } /* - * This gets called the first time a category is referenced and performs the - * initialization. + * This gets called the first time a category is referenced and performs the initialization. * Also resets threshold to inherited! */ -int _xbt_log_cat_init(xbt_log_category_t category, - e_xbt_log_priority_t priority) +int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority) { #define _xbt_log_cat_init(a, b) (0) - if (log_cat_init_mutex != NULL) { - xbt_os_rmutex_acquire(log_cat_init_mutex); - } + if (log_cat_init_mutex != NULL) + xbt_os_mutex_acquire(log_cat_init_mutex); if (category->initialized) { - if (log_cat_init_mutex != NULL) { - xbt_os_rmutex_release(log_cat_init_mutex); - } + if (log_cat_init_mutex != NULL) + xbt_os_mutex_release(log_cat_init_mutex); return priority >= category->threshold; } @@ -938,8 +913,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, xbt_log_setting_t setting = NULL; int found = 0; - XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", - category->name, + XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name, (category->firstChild ? category->firstChild->name : "none"), (category->nextSibling ? category->nextSibling->name : "none")); @@ -948,14 +922,11 @@ int _xbt_log_cat_init(xbt_log_category_t category, category->appender = xbt_log_default_appender; category->layout = xbt_log_default_layout; } else { - if (!category->parent) category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT); - XBT_DEBUG("Set %s (%s) as father of %s ", - category->parent->name, - (category->parent->initialized ? - xbt_log_priority_names[category->parent->threshold] : "uninited"), + XBT_DEBUG("Set %s (%s) as father of %s ", category->parent->name, + (category->parent->initialized ? xbt_log_priority_names[category->parent->threshold] : "uninited"), category->name); xbt_log_parent_set(category, category->parent); @@ -973,14 +944,11 @@ int _xbt_log_cat_init(xbt_log_category_t category, cpp = cpp->nextSibling; } - XBT_DEBUG("Children of %s: %s; nextSibling: %s", - category->parent->name, res, - (category->parent->nextSibling ? - category->parent->nextSibling->name : "none")); + XBT_DEBUG("Children of %s: %s; nextSibling: %s", category->parent->name, res, + (category->parent->nextSibling ? category->parent->nextSibling->name : "none")); free(res); } - } /* Apply the control */ @@ -990,8 +958,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, xbt_dynar_foreach(xbt_log_settings, cursor, setting) { xbt_assert(setting, "Damnit, NULL cat in the list"); - xbt_assert(setting->catname, "NULL setting(=%p)->catname", - (void *) setting); + xbt_assert(setting->catname, "NULL setting(=%p)->catname", (void *) setting); if (!strcmp(setting->catname, category->name)) { found = 1; @@ -1002,14 +969,12 @@ int _xbt_log_cat_init(xbt_log_category_t category, if (!found) XBT_DEBUG("Category '%s': inherited threshold = %s (=%d)", - category->name, xbt_log_priority_names[category->threshold], - category->threshold); + category->name, xbt_log_priority_names[category->threshold], category->threshold); } category->initialized = 1; - if (log_cat_init_mutex != NULL) { - xbt_os_rmutex_release(log_cat_init_mutex); - } + if (log_cat_init_mutex != NULL) + xbt_os_mutex_release(log_cat_init_mutex); return priority >= category->threshold; #undef _xbt_log_cat_init @@ -1022,7 +987,6 @@ void xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent) /* if the category is initialized, unlink from current parent */ if (cat->initialized) { - xbt_log_category_t *cpp = &cat->parent->firstChild; while (*cpp != cat && *cpp != NULL) { @@ -1048,31 +1012,25 @@ void xbt_log_parent_set(xbt_log_category_t cat, xbt_log_category_t parent) static void _set_inherited_thresholds(xbt_log_category_t cat) { - xbt_log_category_t child = cat->firstChild; for (; child != NULL; child = child->nextSibling) { if (child->isThreshInherited) { if (cat != &_XBT_LOGV(log)) XBT_VERB("Set category threshold of %s to %s (=%d)", - child->name, xbt_log_priority_names[cat->threshold], - cat->threshold); + child->name, xbt_log_priority_names[cat->threshold], cat->threshold); child->threshold = cat->threshold; _set_inherited_thresholds(child); } } - - } -void xbt_log_threshold_set(xbt_log_category_t cat, - e_xbt_log_priority_t threshold) +void xbt_log_threshold_set(xbt_log_category_t cat, e_xbt_log_priority_t threshold) { cat->threshold = threshold; cat->isThreshInherited = 0; _set_inherited_thresholds(cat); - } static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) @@ -1097,7 +1055,6 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) dot = control_string; control_string += strcspn(control_string, ":= "); eq = control_string; - control_string += strcspn(control_string, " "); if(*dot != '.' && (*eq == '=' || *eq == ':')) xbt_die ("Invalid control string '%s'", orig_control_string); @@ -1123,22 +1080,20 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) if(ithresh = (e_xbt_log_priority_t) i; } else { THROWF(arg_error, 0, - "Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)", - eq + 1); + "Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)", eq + 1); } free(neweq); } else if (!strncmp(dot + 1, "add", (size_t) (eq - dot - 1)) || !strncmp(dot + 1, "additivity", (size_t) (eq - dot - 1))) { - char *neweq = xbt_strdup(eq + 1); char *p = neweq - 1; @@ -1147,8 +1102,7 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) *p -= 'a' - 'A'; } } - if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES") - || !strcmp(neweq, "1")) { + if (!strcmp(neweq, "ON") || !strcmp(neweq, "YES") || !strcmp(neweq, "1")) { set->additivity = 1; } else { set->additivity = 0; @@ -1156,15 +1110,14 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) free(neweq); } else if (!strncmp(dot + 1, "app", (size_t) (eq - dot - 1)) || !strncmp(dot + 1, "appender", (size_t) (eq - dot - 1))) { - char *neweq = xbt_strdup(eq + 1); if (!strncmp(neweq, "file:", 5)) { set->appender = xbt_log_appender_file_new(neweq + 5); }else if (!strncmp(neweq, "rollfile:", 9)) { - set->appender = xbt_log_appender2_file_new(neweq + 9,1); + set->appender = xbt_log_appender2_file_new(neweq + 9,1); }else if (!strncmp(neweq, "splitfile:", 10)) { - set->appender = xbt_log_appender2_file_new(neweq + 10,0); + set->appender = xbt_log_appender2_file_new(neweq + 10,0); } else { THROWF(arg_error, 0, "Unknown appender log type: '%s'", neweq); } @@ -1173,9 +1126,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) set->fmt = xbt_strdup(eq + 1); } else { char buff[512]; - snprintf(buff, min(512, eq - dot), "%s", dot + 1); - THROWF(arg_error, 0, "Unknown setting of the log category: '%s'", - buff); + snprintf(buff, MIN(512, eq - dot), "%s", dot + 1); + THROWF(arg_error, 0, "Unknown setting of the log category: '%s'", buff); } set->catname = (char *) xbt_malloc(dot - name + 1); @@ -1186,8 +1138,7 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) return set; } -static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat, - char *name) +static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat, char *name) { xbt_log_category_t child, res; @@ -1215,20 +1166,16 @@ static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat, * * ( [category] "." [keyword] ":" value (" ")... )... * - * where [category] is one the category names (see \ref XBT_log_cats for - * a complete list of the ones defined in the SimGrid library) - * and keyword is one of the following: + * where [category] is one the category names (see \ref XBT_log_cats for a complete list of the ones defined in the + * SimGrid library) and keyword is one of the following: * * - thres: category's threshold priority. Possible values: * TRACE,DEBUG,VERBOSE,INFO,WARNING,ERROR,CRITICAL - * - add or additivity: whether the logging actions must be passed to - * the parent category. + * - add or additivity: whether the logging actions must be passed to the parent category. * Possible values: 0, 1, no, yes, on, off. * Default value: yes. * - fmt: the format to use. See \ref log_use_conf_fmt for more information. - * - app or appender: the appender to use. See \ref log_use_conf_app for more - * information. - * + * - app or appender: the appender to use. See \ref log_use_conf_app for more information. */ void xbt_log_control_set(const char *control_string) { @@ -1250,8 +1197,7 @@ void xbt_log_control_set(const char *control_string) } /* some initialization if this is the first time that this get called */ if (xbt_log_settings == NULL) - xbt_log_settings = xbt_dynar_new(sizeof(xbt_log_setting_t), - _free_setting); + xbt_log_settings = xbt_dynar_new(sizeof(xbt_log_setting_t), _free_setting); /* split the string, and remove empty entries */ set_strings = xbt_str_split_quoted(control_string); @@ -1261,21 +1207,18 @@ void xbt_log_control_set(const char *control_string) return; } - /* Parse each entry and either use it right now (if the category was already - created), or store it for further use */ + /* Parse each entry and either use it right now (if the category was already created), or store it for further use */ xbt_dynar_foreach(set_strings, cpt, str) { xbt_log_category_t cat = NULL; set = _xbt_log_parse_setting(str); - cat = - _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname); + cat = _xbt_log_cat_searchsub(&_XBT_LOGV(XBT_LOG_ROOT_CAT), set->catname); if (cat) { XBT_DEBUG("Apply directly"); _xbt_log_cat_apply_set(cat, set); _free_setting((void *) &set); } else { - XBT_DEBUG("Store for further application"); XBT_DEBUG("push %p to the settings", (void *) set); xbt_dynar_push(xbt_log_settings, &set); @@ -1298,9 +1241,7 @@ void xbt_log_layout_set(xbt_log_category_t cat, xbt_log_layout_t lay) { #define _xbt_log_cat_init(a, b) (0) if (!cat->appender) { - XBT_VERB - ("No appender to category %s. Setting the file appender as default", - cat->name); + XBT_VERB ("No appender to category %s. Setting the file appender as default", cat->name); xbt_log_appender_set(cat, xbt_log_appender_file_new(NULL)); } if (cat->layout) { @@ -1378,8 +1319,7 @@ static int xbt_log_cat_cmp(const void *pa, const void *pb) return strcmp(a->name, b->name); } -static void xbt_log_help_categories_rec(xbt_log_category_t category, - const char *prefix) +static void xbt_log_help_categories_rec(xbt_log_category_t category, const char *prefix) { char *this_prefix; char *child_prefix;