Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No need to rebuild the parser if you're not a maintainer.
[simgrid.git] / src / xbt / log.c
index 595576a..205a479 100644 (file)
@@ -2,11 +2,10 @@
 
 /* log - a generic logging facility in the spirit of log4j                  */
 
-/* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+/* Copyright (c) 2003, 2004 Martin Quinson. 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. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <stdarg.h>
 #include <ctype.h>
@@ -50,10 +49,42 @@ s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = {
   NULL, 0
 };
 
-XBT_LOG_NEW_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories");
-XBT_LOG_NEW_SUBCATEGORY(xbt,XBT_LOG_ROOT_CAT,"All XBT categories (gras toolbox)");
+XBT_LOG_NEW_SUBCATEGORY(xbt,XBT_LOG_ROOT_CAT,"All XBT categories (simgrid toolbox)");
+XBT_LOG_NEW_SUBCATEGORY(surf,XBT_LOG_ROOT_CAT,"All SURF categories");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log,xbt,"Loggings from the logging mecanism itself");
 
+void xbt_log_init(int *argc,char **argv, const char *defaultlog) {
+  int i,j;
+  char *opt;
+  int found=0;
+
+  /** Set logs and init log submodule */
+  for (i=1; i<*argc; i++) {
+    if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
+      found = 1;
+      opt=strchr(argv[i],'=');
+      opt++;
+      xbt_log_control_set(opt);
+      DEBUG1("Did apply '%s' as log setting",opt);
+      /*remove this from argv*/
+      for (j=i+1; j<*argc; j++) {
+       argv[j-1] = argv[j];
+      } 
+      argv[j-1] = NULL;
+      (*argc)--;
+      i--; /* compensate effect of next loop incrementation */
+    }
+  }
+  if (!found && defaultlog) {
+     xbt_log_control_set(defaultlog);
+  }
+}
+
+void xbt_log_exit(void) {
+  VERB0("Exiting log");
+  xbt_dynar_free(&xbt_log_settings);
+  VERB0("Exited log");
+}
 
 static void _apply_control(xbt_log_category_t cat) {
   int cursor;
@@ -293,8 +324,8 @@ static void _cleanup_double_spaces(char *s) {
 }
 
 /**
- * xbt_log_control_set:
- * @cs: What to parse
+ * \ingroup XBT_log  
+ * \param control_string What to parse
  *
  * Typically passed a command-line argument. The string has the syntax:
  *
@@ -306,7 +337,7 @@ static void _cleanup_double_spaces(char *s) {
  *      thresh         value is an integer priority level. Sets the category's
  *                        threshold priority.
  *
- * @warning
+ * \warning
  * This routine may only be called once and that must be before any other
  * logging command! Typically, this is done from main().
  */
@@ -363,8 +394,3 @@ void xbt_log_appender_set(xbt_log_category_t cat, xbt_log_appender_t app) {
   cat->appender = app;
 }
 
-void xbt_log_exit(void) {
-  VERB0("Exiting log");
-  xbt_dynar_free(&xbt_log_settings);
-  VERB0("Exited log");
-}