X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/092910cd23c789eb83b53efb69e85ae58ed3b1d0..2f63dce7911dd967b5fd4acadc46a6010c8c0662:/src/xbt/log_default_appender.c?ds=sidebyside diff --git a/src/xbt/log_default_appender.c b/src/xbt/log_default_appender.c index d385a7166b..53c2126b28 100644 --- a/src/xbt/log_default_appender.c +++ b/src/xbt/log_default_appender.c @@ -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 +/* 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 +GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log); + + /** * 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 { @@ -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; -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. - const char *pn; - char buf[20]; // 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->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, gras_log_priority_names[ev->priority]); + vfprintf(stderr, fmt, ev->ap); fprintf(stderr, "\n"); }