Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define correctly variables for windows.
[simgrid.git] / src / xbt / log.c
index b1f767c..bcd94e9 100644 (file)
@@ -1,8 +1,7 @@
-/* $Id$ */
-
 /* log - a generic logging facility in the spirit of log4j                  */
 
-/* Copyright (c) 2003-2007 Martin Quinson. All rights reserved.             */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -469,7 +468,6 @@ welcome here, too.
 
 xbt_log_appender_t xbt_log_default_appender = NULL;     /* set in log_init */
 xbt_log_layout_t xbt_log_default_layout = NULL; /* set in log_init */
-int _log_usable = 0;
 
 typedef struct {
   char *catname;
@@ -518,27 +516,29 @@ XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)");
 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
 XBT_LOG_NEW_CATEGORY(msg, "All MSG categories");
 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
+XBT_LOG_NEW_CATEGORY(mc, "All MC categories");
+XBT_LOG_NEW_CATEGORY(bindings, "All bindings categories");
 
 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) */
+void xbt_log_preinit(void) {
+  xbt_log_default_appender = xbt_log_appender_file_new(NULL);
+  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;
+}
+
 /** @brief Get all logging settings from the command line
  *
  * xbt_log_control_set() is called on each string we got from cmd line
  */
-void xbt_log_init(int *argc, char **argv)
-{
+void xbt_log_init(int *argc, char **argv) {
   int i, j;
   char *opt;
 
-  /* create the default appender and install it in the root category,
-     which were already created (damnit. Too slow little beetle) */
-  xbt_log_default_appender = xbt_log_appender_file_new(NULL);
-  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_usable = 1;
-
   //    _XBT_LOGV(log).threshold = xbt_log_priority_debug; /* uncomment to set the LOG category to debug directly */
 
   /* Set logs and init log submodule */
@@ -591,26 +591,17 @@ static void log_cat_exit(xbt_log_category_t cat)
     log_cat_exit(child);
 }
 
-void xbt_log_exit(void)
+void xbt_log_postexit(void)
 {
   VERB0("Exiting log");
   xbt_dynar_free(&xbt_log_settings);
   log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT));
-  _log_usable = 0;
 }
 
 void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
 {
 
   xbt_log_category_t cat = ev->cat;
-  if (!_log_usable) {
-    /* Make sure that the layouts have been malloced */
-    xbt_log_default_appender = xbt_log_appender_file_new(NULL);
-    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_usable = 1;
-  }
 
   va_start(ev->ap, fmt);
   va_start(ev->ap_copy, fmt);
@@ -630,7 +621,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
   va_end(ev->ap);
   va_end(ev->ap_copy);
 
-#ifdef WIN32
+#ifdef _XBT_WIN32
   free(ev->buffer);
 #endif
 }