Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First attempt to display log categoy hierarchy.
[simgrid.git] / include / xbt / log.h
index 8ffe99f..3b77db3 100644 (file)
@@ -1,6 +1,6 @@
 /* log - a generic logging facility in the spirit of log4j                  */
 
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
 /* XBT_LOG_MAYDAY: define this to replace the logging facilities with basic
    printf function. Useful to debug the logging facilities themselves */
-#include "gras_config.h"
 #undef XBT_LOG_MAYDAY
 //#define XBT_LOG_MAYDAY
-#ifdef _WIN64
-       #define XBT_LOG_MAYDAY
-#endif
 
 #ifndef _XBT_LOG_H_
 #define _XBT_LOG_H_
@@ -117,10 +113,20 @@ typedef enum {
  */
 #if 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)
+# define XBT_LOG_CONNECT(child, parent_cat)                             \
+  if (1) {                                                              \
+    XBT_LOG_EXTERNAL_CATEGORY(child);                                   \
+    XBT_LOG_EXTERNAL_CATEGORY(parent_cat);                              \
+    _XBT_LOGV(child).parent = &_XBT_LOGV(parent_cat);                   \
+  } else ((void)0)
 #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)) */
+# define XBT_LOG_CONNECT(child, parent_cat)                             \
+  if (1) {                                                              \
+    XBT_LOG_EXTERNAL_CATEGORY(child);                                   \
+    XBT_LOG_EXTERNAL_CATEGORY(parent_cat);                              \
+    xbt_assert(_XBT_LOGV(child).parent == &_XBT_LOGV(parent_cat));      \
+  } else ((void)0)
 #endif
 
 /* XBT_LOG_NEW_SUBCATEGORY_helper:
@@ -133,6 +139,7 @@ typedef enum {
         NULL /* firstChild */,                          \
        NULL /* nextSibling */,                         \
         #catName,                                       \
+        0 /*initialized */,                             \
         xbt_log_priority_uninitialized /* threshold */, \
         1 /* isThreshInherited */,                      \
         NULL /* appender */,                            \
@@ -245,16 +252,13 @@ typedef struct xbt_log_category_s s_xbt_log_category_t,
 /*
  * Do NOT access any members of this structure directly. FIXME: move to private?
  */
-#ifdef _XBT_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;
   xbt_log_category_t nextSibling;
   const char *name;
+  int initialized;
   int threshold;
   int isThreshInherited;
   xbt_log_appender_t appender;
@@ -269,12 +273,8 @@ struct xbt_log_event_s {
   const char *functionName;
   int lineNum;
   va_list ap;
-  va_list ap_copy;              /* need a copy to launch dynamic layouts when the static ones overflowed */
-#ifdef _XBT_WIN32
   char *buffer;
-#else
-  char buffer[XBT_LOG_BUFF_SIZE];
-#endif
+  int buffer_size;
 };
 
 /**
@@ -354,6 +354,20 @@ extern xbt_log_layout_t xbt_log_default_layout;
 /* Public functions again */
 /* ********************** */
 
+/**
+ * \ingroup XBT_log
+ *
+ * Prints some help about using the logging infrastructure.
+ */
+XBT_PUBLIC(void) xbt_log_help(void);
+
+/**
+ * \ingroup XBT_log
+ *
+ * Prints the log category hierarchy.
+ */
+XBT_PUBLIC(void) xbt_log_help_categories(void);
+
 /**
  * \ingroup XBT_log 
  * \param catName name of the category
@@ -373,13 +387,12 @@ extern xbt_log_layout_t xbt_log_default_layout;
  *
  * NOTES
  * First part is a compile-time constant.
- * Call to _log_initCat only happens once.
+ * Call to xbt_log_cat_init only happens once.
  */
 #define _XBT_LOG_ISENABLEDV(catv, priority)                  \
        (priority >= XBT_LOG_STATIC_THRESHOLD                 \
-        && priority >= catv.threshold                         \
-        && (catv.threshold != xbt_log_priority_uninitialized \
-            || _xbt_log_cat_init(&catv, priority)) )
+        && (catv.initialized || _xbt_log_cat_init(&catv, priority)) \
+        && priority >= catv.threshold)
 
 /*
  * Internal Macros
@@ -393,15 +406,6 @@ extern xbt_log_layout_t xbt_log_default_layout;
  * code. 
  * Setting the LogEvent's valist member is done inside _log_logEvent.
  */
-#ifdef _XBT_WIN32
-#include <stdlib.h>             /* calloc */
-#define _XBT_LOG_EV_BUFFER_ZERO() \
-  _log_ev.buffer = (char*) calloc(XBT_LOG_BUFF_SIZE + 1, sizeof(char))
-#else
-#include <string.h>             /* memset */
-#define _XBT_LOG_EV_BUFFER_ZERO() \
-  memset(_log_ev.buffer, 0, XBT_LOG_BUFF_SIZE)
-#endif
 
 /* Logging Macros */
 
@@ -423,7 +427,6 @@ extern xbt_log_layout_t xbt_log_default_layout;
       _log_ev.fileName = __FILE__;                                      \
       _log_ev.functionName = _XBT_FUNCTION;                             \
       _log_ev.lineNum = __LINE__;                                       \
-      _XBT_LOG_EV_BUFFER_ZERO();                                        \
       _xbt_log_event_log(&_log_ev, __VA_ARGS__);                        \
     }                                                                   \
   }  while (0)