Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move the stack as field of SafetyChecker and CommDetChecker
[simgrid.git] / src / xbt / xbt_log_layout_simple.c
1 /* layout_simple - a dumb log layout                                        */
2
3 /* Copyright (c) 2007-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "xbt/sysdep.h"
10 #include "xbt/strbuff.h"        /* For dynamic version when the static one fails */
11 #include "src/xbt/log_private.h"
12
13 #include "simgrid/simix.h"      /* SIMIX_host_self_get_name */
14 #include "surf/surf.h"
15 #include <stdio.h>
16 #include "src/internal_config.h"
17
18 extern const char *xbt_log_priority_names[8];
19 extern int xbt_log_no_loc;
20
21 static double simple_begin_of_time = -1;
22
23 #define check_overflow(len)                                             \
24   if ((rem_size -= (len)) > 0) {                                        \
25     p += (len);                                                         \
26   } else                                                                \
27     return 0
28
29 static int xbt_log_layout_simple_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *fmt)
30 {
31   char *p = ev->buffer;
32   int rem_size = ev->buffer_size;
33   const char *procname;
34   int len;
35
36   *p = '[';
37   check_overflow(1);
38
39   /* Display the proc info if available */
40   procname = xbt_procname();
41   if (procname && strcmp(procname,"maestro")) {
42     len = snprintf(p, rem_size, "%s:%s:(%d) ", SIMIX_host_self_get_name(), procname, xbt_getpid());
43     check_overflow(len);
44   }
45   else if (!procname)  {
46   len = snprintf(p, rem_size, "%s::(%d) ", SIMIX_host_self_get_name(), xbt_getpid());
47   check_overflow(len);
48   }
49
50   /* Display the date */
51   len = snprintf(p, rem_size, "%f] ", surf_get_clock() - simple_begin_of_time);
52   check_overflow(len);
53
54   /* Display file position if not INFO */
55   if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc) {
56     len = snprintf(p, rem_size, "%s:%d: ", ev->fileName, ev->lineNum);
57     check_overflow(len);
58   }
59
60   /* Display category name */
61   len = snprintf(p, rem_size, "[%s/%s] ", ev->cat->name, xbt_log_priority_names[ev->priority]);
62   check_overflow(len);
63
64   /* Display user-provided message */
65   len = vsnprintf(p, rem_size, fmt, ev->ap);
66   check_overflow(len);
67
68   /* End it */
69   *p = '\n';
70   check_overflow(1);
71   *p = '\0';
72
73   return 1;
74 }
75
76 xbt_log_layout_t xbt_log_layout_simple_new(char *arg)
77 {
78   xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t, 1);
79   res->do_layout = xbt_log_layout_simple_doit;
80
81   if (simple_begin_of_time < 0)
82     simple_begin_of_time = surf_get_clock();
83
84   return res;
85 }