Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Teach gcc how to check the format and arguments type of debugging functions
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 24 Jul 2004 00:23:17 +0000 (00:23 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 24 Jul 2004 00:23:17 +0000 (00:23 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@324 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/log.c
src/xbt/log_default_appender.c

index 7fa6998..182f1fa 100644 (file)
@@ -8,6 +8,7 @@
 /* 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. */
 
 /* 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. */
 
+
 #include "Core/core_interface.h"
 #include "gras_private.h"
 #include <stdarg.h>
 #include "Core/core_interface.h"
 #include "gras_private.h"
 #include <stdarg.h>
@@ -75,30 +76,30 @@ static void _apply_control(gras_log_category_t* cat) {
 
       if (cat->threshold <= gras_log_priority_verbose) {
        gras_log_event_t _log_ev = 
 
       if (cat->threshold <= gras_log_priority_verbose) {
        gras_log_event_t _log_ev = 
-         {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__,
-          "Apply settings for category '%s': set threshold to %s (=%d)",};
-       _gras_log_event_log(&_log_ev, cat->name,
-                           gras_log_priority_names[cat->threshold], cat->threshold);
+         {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__};
+       _gras_log_event_log(&_log_ev, cat->name, 
+                  "Apply settings for category '%s': set threshold to %s (=%d)",
+                  gras_log_priority_names[cat->threshold], cat->threshold);
       }
     }
   }
   if (!found && cat->threshold <= gras_log_priority_verbose) {
     gras_log_event_t _log_ev = 
       }
     }
   }
   if (!found && cat->threshold <= gras_log_priority_verbose) {
     gras_log_event_t _log_ev = 
-      {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__,
-       "Category '%s': inherited threshold = %s (=%d)",};
+      {cat,gras_log_priority_verbose,__FILE__,__FUNCTION__,__LINE__};
     _gras_log_event_log(&_log_ev, cat->name,
     _gras_log_event_log(&_log_ev, cat->name,
+                       "Category '%s': inherited threshold = %s (=%d)",
                        gras_log_priority_names[cat->threshold], cat->threshold);
   }
 
 }
 
                        gras_log_priority_names[cat->threshold], cat->threshold);
   }
 
 }
 
-void _gras_log_event_log( gras_log_event_t* ev, ...) {
+void _gras_log_event_log( gras_log_event_t* ev, const char *fmt, ...) {
   gras_log_category_t* cat = ev->cat;
   gras_log_category_t* cat = ev->cat;
-  va_start(ev->ap, ev);
+  va_start(ev->ap, fmt);
   while(1) {
     gras_log_appender_t* appender = cat->appender;
     if (appender != NULL) {
   while(1) {
     gras_log_appender_t* appender = cat->appender;
     if (appender != NULL) {
-      appender->do_append(appender, ev);
+      appender->do_append(appender, ev, fmt);
     }
     if (!cat->willLogToParent)
       break;
     }
     if (!cat->willLogToParent)
       break;
index d385a71..53c2126 100644 (file)
@@ -1,38 +1,27 @@
-// $Id$
-// Copyright (c) 2001, Bit Farm, Inc. All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-// 1. Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the distribution.
-// 3. The name of the author may not be used to endorse or promote products
-//    derived from this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* $Id$ */
 
 
-#include <gras.h>
+/* file_appender - a dumb log appender which simply prints to stdout        */
+
+/* Authors: Martin Quinson                                                  */
+/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+
+/* 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. */
+
+#include "gras_private.h"
 #include <stdio.h>
 
 #include <stdio.h>
 
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log);
+
+
 /**
  * The root category's default logging function.
  */
 
 extern const char *gras_log_priority_names[7];
 
 /**
  * The root category's default logging function.
  */
 
 extern const char *gras_log_priority_names[7];
 
-static void append_file(gras_log_appender_t* this, gras_log_event_t* ev);
+static void append_file(gras_log_appender_t* this, gras_log_event_t* ev,
+                       const char *fmt);
 
 /*
 struct gras_log_appender_file_s {
 
 /*
 struct gras_log_appender_file_s {
@@ -46,28 +35,25 @@ static gras_log_appender_t gras_log_appender_file = { append_file, NULL } ;
 
 gras_log_appender_t* gras_log_default_appender  = &gras_log_appender_file;
 
 
 gras_log_appender_t* gras_log_default_appender  = &gras_log_appender_file;
 
-static void append_file(gras_log_appender_t* this, gras_log_event_t* ev) {
+static void append_file(gras_log_appender_t* this, 
+                       gras_log_event_t* ev, 
+                       const char *fmt) {
 
     // TODO: define a format field in struct for timestamp, etc.
 
     // TODO: define a format field in struct for timestamp, etc.
-    const char *pn;
-    char buf[20];
     //    struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0;
     
     if ((FILE*)(this->appender_data) == NULL)
       this->appender_data = (void*)stderr;
     
     //    struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0;
     
     if ((FILE*)(this->appender_data) == NULL)
       this->appender_data = (void*)stderr;
     
-    if (ev->priority < 0) {
-        pn = "Negative Priority NOT ALLOWED!!";
-    }
-    else if (ev->priority < sizeof(gras_log_priority_names)) {
-        pn = gras_log_priority_names[ev->priority];
-    } else {
-        sprintf(buf, "%s+%d",
-                gras_log_priority_names[sizeof(gras_log_priority_names)-1],
-                ev->priority - sizeof(gras_log_priority_names) + 1);
-    }
+    gras_assert0(ev->priority>=0,
+                "Negative logging priority naturally forbidden");
+    gras_assert1(ev->priority<sizeof(gras_log_priority_names),
+                "Priority %d is greater than the biggest allowed value",
+                ev->priority);
+
     fprintf(stderr, "%s:%d: ", ev->fileName, ev->lineNum);
     fprintf(stderr, "%s:%d: ", ev->fileName, ev->lineNum);
-    fprintf(stderr, "[%s/%s] ", ev->cat->name,pn);
-    vfprintf(stderr, ev->fmt, ev->ap);
+    fprintf(stderr, "[%s/%s] ", 
+           ev->cat->name, gras_log_priority_names[ev->priority]);
+    vfprintf(stderr, fmt, ev->ap);
     fprintf(stderr, "\n");
 }
     fprintf(stderr, "\n");
 }