2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <urcu/tls-compat.h>
29 #error "lttng-tools error.h needs _GNU_SOURCE"
32 #include <lttng/lttng-error.h>
33 #include <common/compat/tid.h>
35 /* Stringify the expansion of a define */
36 #define XSTR(d) STR(d)
40 * Contains the string of the log entry time. This is used as a thread local
41 * storage so we don't race between thread and also avoid memory allocation
42 * every time a log is fired.
45 /* Format: 00:00:00.000000 plus NULL byte. */
48 extern DECLARE_URCU_TLS(struct log_time
, error_log_time
);
50 extern int lttng_opt_quiet
;
51 extern int lttng_opt_verbose
;
55 #define PRINT_WARN 0x2
58 #define PRINT_DBG 0x10
59 #define PRINT_DBG2 0x20
60 #define PRINT_DBG3 0x30
63 * Macro for printing message depending on command line option and verbosity.
65 #define __lttng_print(type, fmt, args...) \
67 if (lttng_opt_quiet == 0 && type == PRINT_MSG) { \
68 fprintf(stdout, fmt, ## args); \
69 } else if (lttng_opt_quiet == 0 && \
70 (((type & PRINT_DBG) && lttng_opt_verbose == 1) || \
71 ((type & (PRINT_DBG | PRINT_DBG2)) && \
72 lttng_opt_verbose == 2) || \
73 ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \
74 lttng_opt_verbose == 3))) { \
75 fprintf(stderr, fmt, ## args); \
76 } else if (lttng_opt_quiet == 0 && (type & (PRINT_WARN))) { \
77 fprintf(stderr, fmt, ## args); \
78 } else if (type & (PRINT_ERR | PRINT_BUG)) { \
79 fprintf(stderr, fmt, ## args); \
83 /* Three level of debug. Use -v, -vv or -vvv for the levels */
84 #define _ERRMSG(msg, type, fmt, args...) __lttng_print(type, msg \
85 " - %s [%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
86 log_add_time(), (long) getpid(), (long) gettid(), ## args, __func__)
88 #define MSG(fmt, args...) \
89 __lttng_print(PRINT_MSG, fmt "\n", ## args)
90 #define _MSG(fmt, args...) \
91 __lttng_print(PRINT_MSG, fmt, ## args)
92 #define ERR(fmt, args...) \
93 __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
94 #define WARN(fmt, args...) \
95 __lttng_print(PRINT_ERR, "Warning: " fmt "\n", ## args)
97 #define BUG(fmt, args...) _ERRMSG("BUG", PRINT_BUG, fmt, ## args)
99 #define DBG(fmt, args...) _ERRMSG("DEBUG1", PRINT_DBG, fmt, ## args)
100 #define DBG2(fmt, args...) _ERRMSG("DEBUG2", PRINT_DBG2, fmt, ## args)
101 #define DBG3(fmt, args...) _ERRMSG("DEBUG3", PRINT_DBG3, fmt, ## args)
103 #define _PERROR(fmt, args...) _ERRMSG("PERROR", PRINT_ERR, fmt, ## args)
105 #if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
108 * Version using XSI strerror_r.
110 #define PERROR(call, args...) \
113 strerror_r(errno, buf, sizeof(buf)); \
114 _PERROR(call ": %s", ## args, buf); \
118 * Version using GNU strerror_r, for linux with appropriate defines.
120 #define PERROR(call, args...) \
124 buf = strerror_r(errno, tmp, sizeof(tmp)); \
125 _PERROR(call ": %s", ## args, buf); \
129 const char *error_get_str(int32_t code
);
132 * Function that format the time and return the reference of log_time.str to
133 * the caller. On error, an empty string is returned thus no time will be
134 * printed in the log.
136 const char *log_add_time();
138 #endif /* _ERROR_H */
This page took 0.03236 seconds and 4 git commands to generate.