Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9185cb2e5dcbe9002e03d518ec8f27ce6fa84db2
[simgrid.git] / src / xbt / xbt_log_layout_simple.c
1 /* $Id$ */
2
3 /* layout_simple - a dumb log layout                                        */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12 #include "xbt/synchro.h" /* xbt_thread_name */
13 #include "gras/virtu.h"
14 #include <stdio.h>
15
16 extern const char *xbt_log_priority_names[7];
17
18 static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
19                                        xbt_log_event_t ev, 
20                                        const char *fmt) {
21   static double begin_of_time = -1;
22   char *p;  
23
24   xbt_assert0(ev->priority>=0,
25               "Negative logging priority naturally forbidden");
26   xbt_assert1(ev->priority<sizeof(xbt_log_priority_names),
27               "Priority %d is greater than the biggest allowed value",
28               ev->priority);
29
30   if (begin_of_time<0) 
31     begin_of_time=gras_os_time();
32
33   p = ev->buffer;
34   p += sprintf(p,"[");;
35   /* Display the proc info if available */
36   if(strlen(xbt_procname()))
37     p += sprintf(p,"%s:%s:(%d) ", 
38                  gras_os_myname(), xbt_procname(),(*xbt_getpid)());
39
40   /* Display the date */
41   p += sprintf(p,"%f] ", gras_os_time()-begin_of_time);
42
43
44   /* Display file position if not INFO*/
45   if (ev->priority != xbt_log_priority_info)
46     p += sprintf(p, "%s:%d: ", ev->fileName, ev->lineNum);
47
48   /* Display category name */
49   p += sprintf(p, "[%s/%s] ", 
50                ev->cat->name, xbt_log_priority_names[ev->priority] );
51
52   /* Display user-provided message */
53   p += vsprintf(p, fmt, ev->ap);
54
55   /* End it */
56   p += sprintf(p, "\n");
57
58 }
59
60 xbt_log_layout_t xbt_log_layout_simple_new(char *arg) {
61   xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t,1);
62   res->do_layout = xbt_log_layout_simple_doit;
63   return res;
64 }