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 "src/xbt/log_private.h"
12 #include "simgrid/simix.h" /* SIMIX_host_self_get_name */
13 #include "surf/surf.h"
15 #include "src/internal_config.h"
17 extern const char *xbt_log_priority_names[8];
18 extern int xbt_log_no_loc;
20 static double simple_begin_of_time = -1;
22 #define check_overflow(len) \
23 if ((rem_size -= (len)) > 0) { \
28 static int xbt_log_layout_simple_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *fmt)
31 int rem_size = ev->buffer_size;
38 /* Display the proc info if available */
39 procname = xbt_procname();
40 if (procname && strcmp(procname,"maestro")) {
41 len = snprintf(p, rem_size, "%s:%s:(%d) ", SIMIX_host_self_get_name(), procname, xbt_getpid());
45 len = snprintf(p, rem_size, "%s::(%d) ", SIMIX_host_self_get_name(), xbt_getpid());
49 /* Display the date */
50 len = snprintf(p, rem_size, "%f] ", surf_get_clock() - simple_begin_of_time);
53 /* Display file position if not INFO */
54 if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc) {
55 len = snprintf(p, rem_size, "%s:%d: ", ev->fileName, ev->lineNum);
59 /* Display category name */
60 len = snprintf(p, rem_size, "[%s/%s] ", ev->cat->name, xbt_log_priority_names[ev->priority]);
63 /* Display user-provided message */
64 len = vsnprintf(p, rem_size, fmt, ev->ap);
75 xbt_log_layout_t xbt_log_layout_simple_new(char *arg)
77 xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t, 1);
78 res->do_layout = &xbt_log_layout_simple_doit;
80 if (simple_begin_of_time < 0)
81 simple_begin_of_time = surf_get_clock();