Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not truncate the output on large messages, but switch to a dynamically allocated...
[simgrid.git] / src / xbt / log.c
index 0a3a659..d158ee5 100644 (file)
@@ -2,7 +2,7 @@
 
 /* log - a generic logging facility in the spirit of log4j                  */
 
-/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
+/* Copyright (c) 2003-2007 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. */
@@ -20,7 +20,7 @@
 #include "xbt/misc.h"
 #include "xbt/ex.h"
 #include "xbt/sysdep.h"
-#include "xbt/log.h"
+#include "xbt/log_private.h"
 #include "xbt/dynar.h"
 
 XBT_PUBLIC_DATA(int) (*xbt_pid)();
@@ -582,12 +582,12 @@ void _xbt_log_event_log( xbt_log_event_t ev, const char *fmt, ...) {
   }
    
   va_start(ev->ap, fmt);
+  va_start(ev->ap_copy, fmt);
   while(1) {
     xbt_log_appender_t appender = cat->appender;
     if (appender != NULL) {
       xbt_assert1(cat->layout,"No valid layout for the appender of category %s",cat->name);
-      cat->layout->do_layout(cat->layout, ev, fmt);
-      appender->do_append(appender, ev->buffer);
+      cat->layout->do_layout(cat->layout, ev, fmt, appender);
     }
     if (!cat->additivity)
       break;
@@ -595,6 +595,7 @@ void _xbt_log_event_log( xbt_log_event_t ev, const char *fmt, ...) {
     cat = cat->parent;
   } 
   va_end(ev->ap);
+  va_end(ev->ap_copy);
 }
 
 static void _xbt_log_cat_apply_set(xbt_log_category_t category,
@@ -666,15 +667,18 @@ int _xbt_log_cat_init(xbt_log_category_t category,
   int found = 0;
   s_xbt_log_event_t _log_ev;
 
-  _log_ev.cat = category;
-  _log_ev.priority = xbt_log_priority_debug;
-  _log_ev.fileName = __FILE__ ;
-  _log_ev.functionName = _XBT_FUNCTION ;
-  _log_ev.lineNum = __LINE__ ;
-  _xbt_log_event_log(&_log_ev, "Initializing category '%s' (firstChild=%s, nextSibling=%s)",
-                    category->name, 
-                    (category->firstChild ?category->firstChild->name :"none"),
-                    (category->nextSibling?category->nextSibling->name:"none"));
+  if (_XBT_LOGV(log).threshold <= xbt_log_priority_debug
+      && _XBT_LOGV(log).threshold != xbt_log_priority_uninitialized) {
+     _log_ev.cat = &_XBT_LOGV(log);
+     _log_ev.priority = xbt_log_priority_debug;
+     _log_ev.fileName = __FILE__ ;
+     _log_ev.functionName = _XBT_FUNCTION ;
+     _log_ev.lineNum = __LINE__ ;  
+     _xbt_log_event_log(&_log_ev, "Initializing category '%s' (firstChild=%s, nextSibling=%s)",
+                       category->name, 
+                       (category->firstChild ?category->firstChild->name :"none"),
+                       (category->nextSibling?category->nextSibling->name:"none"));
+  }
    
   if(category == &_XBT_LOGV(XBT_LOG_ROOT_CAT)){
     category->threshold = xbt_log_priority_info;/* xbt_log_priority_debug*/;
@@ -685,13 +689,17 @@ int _xbt_log_cat_init(xbt_log_category_t category,
     if (!category->parent)
       category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT);
     
-    _log_ev.lineNum = __LINE__ ;
-    _xbt_log_event_log(&_log_ev, "Set %s (%s) as father of %s ", category->parent->name,
-                      (category->parent->threshold == xbt_log_priority_uninitialized ? "uninited":xbt_log_priority_names[category->parent->threshold]),
-                      category->name);
+    if (_XBT_LOGV(log).threshold <= xbt_log_priority_debug
+       && _XBT_LOGV(log).threshold != xbt_log_priority_uninitialized) {
+       _log_ev.lineNum = __LINE__ ;
+       _xbt_log_event_log(&_log_ev, "Set %s (%s) as father of %s ", category->parent->name,
+                         (category->parent->threshold == xbt_log_priority_uninitialized ? "uninited":xbt_log_priority_names[category->parent->threshold]),
+                         category->name);
+    }     
     xbt_log_parent_set(category, category->parent);
      
-    if (_XBT_LOGV(log).threshold < xbt_log_priority_info) {
+    if (_XBT_LOGV(log).threshold < xbt_log_priority_info
+       && _XBT_LOGV(log).threshold != xbt_log_priority_uninitialized) {
        char *buf,*res=NULL;
        xbt_log_category_t cpp = category->parent->firstChild;
        while (cpp) {
@@ -738,7 +746,7 @@ int _xbt_log_cat_init(xbt_log_category_t category,
   
   if (!found && category->threshold <= xbt_log_priority_verbose) {
     
-    _log_ev.cat = category;
+    _log_ev.cat = &_XBT_LOGV(log);
     _log_ev.priority = xbt_log_priority_verbose;
     _log_ev.fileName = __FILE__ ;
     _log_ev.functionName = _XBT_FUNCTION ;