Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I probably had been drinking too much the day I have written this command... Sorry...
[simgrid.git] / src / xbt / log.c
index 65ca648..e76d823 100644 (file)
@@ -2,7 +2,7 @@
 
 /* log - a generic logging facility in the spirit of log4j                  */
 
-/* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
+/* 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. */
@@ -49,11 +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;
@@ -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");
-}