1 /* layout_simple - a dumb log layout */
3 /* Copyright (c) 2007-2014. The SimGrid Team.
4 * All rights reserved. */
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. */
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"
13 #include "simgrid/simix.h" /* SIMIX_host_self_get_name */
14 #include "surf/surf.h"
16 #include "src/portable.h"
18 extern const char *xbt_log_priority_names[8];
19 extern int xbt_log_no_loc;
21 static double simple_begin_of_time = -1;
23 #define check_overflow(len) \
24 if ((rem_size -= (len)) > 0) { \
29 static int xbt_log_layout_simple_doit(xbt_log_layout_t l,
34 int rem_size = ev->buffer_size;
41 /* Display the proc info if available */
42 procname = xbt_procname();
43 if (procname && *procname) {
44 len = snprintf(p, rem_size, "%s:%s:(%d) ",
45 SIMIX_host_self_get_name(), procname, xbt_getpid());
49 len = snprintf(p, rem_size, "%s::(%d) ",
50 SIMIX_host_self_get_name(), xbt_getpid());
54 /* Display the date */
55 len = snprintf(p, rem_size, "%f] ",
56 surf_get_clock() - simple_begin_of_time);
59 /* Display file position if not INFO */
60 if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc) {
61 len = snprintf(p, rem_size, "%s:%d: ",
62 ev->fileName, ev->lineNum);
66 /* Display category name */
67 len = snprintf(p, rem_size, "[%s/%s] ",
68 ev->cat->name, xbt_log_priority_names[ev->priority]);
71 /* Display user-provided message */
72 len = vsnprintf(p, rem_size, fmt, ev->ap);
83 xbt_log_layout_t xbt_log_layout_simple_new(char *arg)
85 xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t, 1);
86 res->do_layout = xbt_log_layout_simple_doit;
88 if (simple_begin_of_time < 0)
89 simple_begin_of_time = surf_get_clock();