X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49c66599a16037090462b50df22bc1c7f14db56b..8fff2e00d4ccc43f92e60bbc971289cd003399af:/include/xbt/log.h diff --git a/include/xbt/log.h b/include/xbt/log.h index f98ba80c20..3d7aabc448 100644 --- a/include/xbt/log.h +++ b/include/xbt/log.h @@ -87,21 +87,53 @@ typedef enum { #endif /* !defined(NLOG) */ /* Transforms a category name to a global variable name. */ -#define _XBT_LOGV(cat) _XBT_LOG_CONCAT(_simgrid_this_log_category_does_not_exist__, cat) +#define _XBT_LOGV(cat) _XBT_LOG_CONCAT(_simgrid_log_category__, cat) #define _XBT_LOG_CONCAT(x,y) x ## y /* The root of the category hierarchy. */ #define XBT_LOG_ROOT_CAT root +/* In stric ansi C, we are not allowed to initialize a variable with + * a non-constant value. But the whole tree of categories is + * connected by setting the address of the parent category as a field + * of the child one. + * + * Unfortunately, Visual C builder does not target any standard + * compliance, and C99 is not an exception to this unfortunate rule. + * + * So, we work this around by adding a XBT_LOG_CONNECT() macro, + * allowing to connect a child to its parent. It should be used + * during the initialization of the code, before the child category + * gets used. + * + * When compiling with gcc, this is not necessary (XBT_LOG_CONNECT + * defines to nothing). When compiling with MSVC, this is needed if + * you don't want to see your child category become a child of root + * directly. + */ +#if defined(__STRICT_ANSI__) || defined(_MSC_VER) +# define _XBT_LOG_PARENT_INITIALIZER(parent) NULL +# define XBT_LOG_CONNECT(parent_cat,child) _XBT_LOGV(child).parent = &_XBT_LOGV(parent_cat) +#else +# define _XBT_LOG_PARENT_INITIALIZER(parent) &_XBT_LOGV(parent) +# define XBT_LOG_CONNECT(parent_cat,child) /* xbt_assert(_XBT_LOGV(child).parent == &_XBT_LOGV(parent_cat))*/ +#endif + /* XBT_LOG_NEW_SUBCATEGORY_helper: * Implementation of XBT_LOG_NEW_SUBCATEGORY, which must declare "extern parent" in addition * to avoid an extra declaration of root when XBT_LOG_NEW_SUBCATEGORY is called by * XBT_LOG_NEW_CATEGORY */ #define XBT_LOG_NEW_SUBCATEGORY_helper(catName, parent, desc) \ XBT_EXPORT_NO_IMPORT(s_xbt_log_category_t) _XBT_LOGV(catName) = { \ - &_XBT_LOGV(parent), 0, 0, \ - #catName, xbt_log_priority_uninitialized, 1, \ - 0, 0, 1 \ + _XBT_LOG_PARENT_INITIALIZER(parent), \ + NULL /* firstChild */, \ + NULL /* nextSibling */, \ + #catName, \ + xbt_log_priority_uninitialized /* threshold */, \ + 1 /* isThreshInherited */, \ + NULL /* appender */, \ + NULL /* layout */, \ + 1 /* additivity */ \ } /** * \ingroup XBT_log @@ -124,17 +156,9 @@ typedef enum { * * Creates a new subcategory of the root category. */ - -/*#if (defined(_WIN32) && !defined(DLL_STATIC)) KILLME? - # define XBT_LOG_NEW_CATEGORY(catName,desc) \ - XBT_EXPORT_NO_IMPORT(s_xbt_log_category_t) _XBT_LOGV(catName) = { \ - 0, 0, 0, \ - #catName, xbt_log_priority_uninitialized, 1, \ - 0, 1 \ - } -#else*/ -# define XBT_LOG_NEW_CATEGORY(catName,desc) XBT_LOG_NEW_SUBCATEGORY_helper(catName, XBT_LOG_ROOT_CAT, desc) -//#endif +# define XBT_LOG_NEW_CATEGORY(catName,desc) \ + XBT_LOG_NEW_SUBCATEGORY_helper(catName, XBT_LOG_ROOT_CAT, desc) + /** * \ingroup XBT_log @@ -160,28 +184,9 @@ typedef enum { * Creates a new subcategory of the root category and makes it the default * (used by macros that don't explicitly specify a category). */ - - /* -#if (defined(_WIN32) && !defined(DLL_STATIC)) -# define XBT_LOG_NEW_ROOT_SUBCATEGORY(cname,desc) \ - XBT_EXPORT_NO_IMPORT(s_xbt_log_category_t) _XBT_LOGV(cname) = { \ - 0, 0, 0, \ - #cname, xbt_log_priority_uninitialized, 1, \ - 0, 1 \ - } -# define XBT_LOG_NEW_DEFAULT_CATEGORY(cname,desc) \ - XBT_LOG_NEW_ROOT_SUBCATEGORY(cname,desc); \ - XBT_LOG_DEFAULT_CATEGORY(cname) - -#else -*/ # define XBT_LOG_NEW_DEFAULT_CATEGORY(cname,desc) \ XBT_LOG_NEW_CATEGORY(cname,desc); \ XBT_LOG_DEFAULT_CATEGORY(cname) - -//#endif - - /** * \ingroup XBT_log @@ -234,6 +239,11 @@ typedef struct xbt_log_category_s s_xbt_log_category_t,*xbt_log_category_t; /* * Do NOT access any members of this structure directly. FIXME: move to private? */ +#ifdef WIN32 +#define XBT_LOG_BUFF_SIZE 16384/* Size of the static string in which we build the log string */ +#else +#define XBT_LOG_BUFF_SIZE 2048 /* Size of the static string in which we build the log string */ +#endif struct xbt_log_category_s { xbt_log_category_t parent; xbt_log_category_t firstChild; @@ -246,27 +256,19 @@ struct xbt_log_category_s { int additivity; }; -struct xbt_log_appender_s { - void (*do_append) (xbt_log_appender_t this_appender, - char *event); - void (*free_) (xbt_log_appender_t this_); - void *data; -}; - -struct xbt_log_layout_s { - char *(*do_layout)(xbt_log_layout_t l, - xbt_log_event_t event, const char *fmt); - void (*free_) (xbt_log_layout_t l); - void *data; -} ; - struct xbt_log_event_s { xbt_log_category_t cat; e_xbt_log_priority_t priority; const char* fileName; const char* functionName; - int lineNum; + int lineNum; va_list ap; + va_list ap_copy; /* need a copy to launch dynamic layouts when the static ones overflowed */ + #ifdef WIN32 + char* buffer; + #else + char buffer[XBT_LOG_BUFF_SIZE]; + #endif }; /** @@ -279,16 +281,6 @@ struct xbt_log_event_s { XBT_PUBLIC(void) xbt_log_threshold_set(xbt_log_category_t cat, e_xbt_log_priority_t thresholdPriority); -/** - * \ingroup XBT_log_implem - * \param cat the category (not only its name, but the variable) - * \param parent the parent cat - * - * Programatically alter a category's parent (don't use). - */ -XBT_PUBLIC(void) xbt_log_parent_set(xbt_log_category_t cat, - xbt_log_category_t parent); - /** * \ingroup XBT_log_implem * \param cat the category (not only its name, but the variable) @@ -345,9 +337,8 @@ XBT_PUBLIC(int) _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority); -extern XBT_IMPORT_NO_EXPORT(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); +XBT_PUBLIC_DATA(s_xbt_log_category_t) _XBT_LOGV(XBT_LOG_ROOT_CAT); -XBT_LOG_EXTERNAL_CATEGORY(GRAS); extern xbt_log_appender_t xbt_log_default_appender; extern xbt_log_layout_t xbt_log_default_layout; @@ -395,14 +386,23 @@ extern xbt_log_layout_t xbt_log_default_layout; * code. * Setting the LogEvent's valist member is done inside _log_logEvent. */ - +#ifdef WIN32 #define _XBT_LOG_PRE(catv, priority) do { \ if (_XBT_LOG_ISENABLEDV(catv, priority)) { \ s_xbt_log_event_t _log_ev = \ - {NULL,priority,__FILE__,_XBT_FUNCTION,__LINE__}; \ + {NULL,priority,__FILE__,_XBT_FUNCTION,__LINE__}; \ + _log_ev.cat = &(catv); \ + _log_ev.buffer = (char*) calloc(XBT_LOG_BUFF_SIZE + 1, sizeof(char)); \ + _xbt_log_event_log(&_log_ev +#else +#define _XBT_LOG_PRE(catv, priority) do { \ + if (_XBT_LOG_ISENABLEDV(catv, priority)) { \ + s_xbt_log_event_t _log_ev = \ + {NULL,priority,__FILE__,_XBT_FUNCTION,__LINE__}; \ _log_ev.cat = &(catv); \ _xbt_log_event_log(&_log_ev \ +#endif #define _XBT_LOG_POST \ ); \