3 /* layout_simple - a dumb log layout */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
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. */
10 #include "portable.h" /* execinfo when available */
11 #include "xbt/sysdep.h"
13 #include "xbt/synchro.h" /* xbt_thread_name */
14 #include "gras/virtu.h"
17 extern const char *xbt_log_priority_names[7];
19 /* only used after the format using: we suppose that the buffer is big enough to display our data */
20 #define check_overflow \
21 if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
22 p=ev->buffer + XBT_LOG_BUFF_SIZE - strlen(" >> OUTPUT TRUNCATED <<\n"); \
23 p+=sprintf(p," >> OUTPUT TRUNCATED <<\n"); \
26 static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
29 static double begin_of_time = -1;
32 xbt_assert0(ev->priority>=0,
33 "Negative logging priority naturally forbidden");
34 xbt_assert1(ev->priority<sizeof(xbt_log_priority_names),
35 "Priority %d is greater than the biggest allowed value",
39 begin_of_time=gras_os_time();
42 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"[");
44 /* Display the proc info if available */
45 if(strlen(xbt_procname()))
46 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"%s:%s:(%d) ",
47 gras_os_myname(), xbt_procname(),(*xbt_getpid)());
49 /* Display the date */
50 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer),"%f] ", gras_os_time()-begin_of_time);
52 /* Display file position if not INFO*/
53 if (ev->priority != xbt_log_priority_info)
54 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "%s:%d: ", ev->fileName, ev->lineNum);
56 /* Display category name */
57 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "[%s/%s] ",
58 ev->cat->name, xbt_log_priority_names[ev->priority] );
60 /* Display user-provided message */
61 p += vsnprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), fmt, ev->ap);
65 p += snprintf(p,XBT_LOG_BUFF_SIZE-(p-ev->buffer), "\n");
69 xbt_log_layout_t xbt_log_layout_simple_new(char *arg) {
70 xbt_log_layout_t res = xbt_new0(s_xbt_log_layout_t,1);
71 res->do_layout = xbt_log_layout_simple_doit;