X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/092910cd23c789eb83b53efb69e85ae58ed3b1d0..de6f834747f9af2af9f110ee3ba3bb9f3f0d01f3:/src/xbt/log_default_appender.c diff --git a/src/xbt/log_default_appender.c b/src/xbt/log_default_appender.c index d385a7166b..7030bb830a 100644 --- a/src/xbt/log_default_appender.c +++ b/src/xbt/log_default_appender.c @@ -1,73 +1,59 @@ -// $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 +/* file_appender - a dumb log appender which simply prints to stdout */ + +/* 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. */ + +#include "xbt/sysdep.h" +#include "xbt/log.h" +#include "xbt/error.h" #include +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log,"default logging handler"); + /** * The root category's default logging function. */ -extern const char *gras_log_priority_names[7]; +extern const char *xbt_log_priority_names[7]; -static void append_file(gras_log_appender_t* this, gras_log_event_t* ev); +static void append_file(xbt_log_appender_t this, xbt_log_event_t ev, + const char *fmt); /* -struct gras_log_appender_file_s { - gras_log_appender_t* appender; +struct xbt_log_appender_file_s { + xbt_log_appender_t* appender; FILE *file; }; */ -static gras_log_appender_t gras_log_appender_file = { append_file, NULL } ; +static s_xbt_log_appender_t xbt_log_appender_file = { append_file, NULL } ; /* appender_data=FILE* */ -gras_log_appender_t* gras_log_default_appender = &gras_log_appender_file; +xbt_log_appender_t xbt_log_default_appender = &xbt_log_appender_file; -static void append_file(gras_log_appender_t* this, gras_log_event_t* ev) { +static void append_file(xbt_log_appender_t this, + xbt_log_event_t ev, + const char *fmt) { - // TODO: define a format field in struct for timestamp, etc. - const char *pn; - char buf[20]; - // struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0; + /* TODO: define a format field in struct for timestamp, etc. + 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); - } + xbt_assert0(ev->priority>=0, + "Negative logging priority naturally forbidden"); + xbt_assert1(ev->prioritypriority); + 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, xbt_log_priority_names[ev->priority]); + vfprintf(stderr, fmt, ev->ap); fprintf(stderr, "\n"); }