Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Comment windows cruft, which does not compile anyway (may need some extra love to...
[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
19 static char *xbt_log_layout_simple_doit(xbt_log_layout_t l,
20                                         xbt_log_event_t ev, 
21                                         const char *fmt) {
22   static char res[1024];
23   static double begin_of_time = -1;
24   char *p;  
25
26   xbt_assert0(ev->priority>=0,
27               "Negative logging priority naturally forbidden");
28   xbt_assert1(ev->priority<sizeof(xbt_log_priority_names),
29               "Priority %d is greater than the biggest allowed value",
30               ev->priority);
31
32   if (begin_of_time<0) 
33     begin_of_time=gras_os_time();
34
35   p = res;
36   p += sprintf(res,"[");;
37   /* Display the proc info if available */
38   if(strlen(xbt_procname()))
39     p += sprintf(p,"%s:%s:(%d):%s ", 
40                  gras_os_myname(), xbt_procname(),(*xbt_getpid)(),xbt_thread_self_name());
41
42   /* Display the date */
43   p += sprintf(p,"%f] ", gras_os_time()-begin_of_time);
44
45
46   /* Display file position if not INFO*/
47   if (ev->priority != xbt_log_priority_info)
48     p += sprintf(p, "%s:%d: ", ev->fileName, ev->lineNum);
49
50   /* Display category name */
51   p += sprintf(p, "[%s/%s] ", 
52                ev->cat->name, xbt_log_priority_names[ev->priority] );
53
54   /* Display user-provided message */
55   p += vsprintf(p, fmt, ev->ap);
56
57   /* End it */
58   p += sprintf(p, "\n");
59
60   return res;
61 }
62
63 xbt_log_layout_t xbt_log_layout_simple_new(char *arg) {
64   xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t,1);
65   res->do_layout = xbt_log_layout_simple_doit;
66   return res;
67 }