Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Version 0.5 (protocol not changed; ABI changed)
[simgrid.git] / src / xbt / log_default_appender.c
1 /* $Id$ */
2
3 /* file_appender - a dumb log appender which simply prints to stdout        */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003, 2004 Martin Quinson.                                 */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "gras_private.h"
12 #include <stdio.h>
13
14 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(log_app,log);
15
16 /**
17  * The root category's default logging function.
18  */
19
20 extern const char *gras_log_priority_names[7];
21
22 static void append_file(gras_log_appender_t* this, gras_log_event_t* ev,
23                         const char *fmt);
24
25 /*
26 struct gras_log_appender_file_s {
27   gras_log_appender_t* appender;
28   FILE *file;
29 };
30 */
31
32 static gras_log_appender_t gras_log_appender_file = { append_file, NULL } ;
33 /* appender_data=FILE* */
34
35 gras_log_appender_t* gras_log_default_appender  = &gras_log_appender_file;
36
37 static void append_file(gras_log_appender_t* this, 
38                         gras_log_event_t* ev, 
39                         const char *fmt) {
40
41     // TODO: define a format field in struct for timestamp, etc.
42     //    struct DefaultLogAppender* this = (struct DefaultLogAppender*)this0;
43     
44     if ((FILE*)(this->appender_data) == NULL)
45       this->appender_data = (void*)stderr;
46     
47     gras_assert0(ev->priority>=0,
48                  "Negative logging priority naturally forbidden");
49     gras_assert1(ev->priority<sizeof(gras_log_priority_names),
50                  "Priority %d is greater than the biggest allowed value",
51                  ev->priority);
52
53     fprintf(stderr, "%s:%d: ", ev->fileName, ev->lineNum);
54     fprintf(stderr, "[%s/%s] ", 
55             ev->cat->name, gras_log_priority_names[ev->priority]);
56     vfprintf(stderr, fmt, ev->ap);
57     fprintf(stderr, "\n");
58 }