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 /* Avoid conflict with Solaris <sys/regset.h> */
36 #if defined(ERR) && defined(__sun__)
40 /* Stringify the expansion of a define */
41 #define XSTR(d) STR(d)
45 * Contains the string of the log entry time. This is used as a thread local
46 * storage so we don't race between thread and also avoid memory allocation
47 * every time a log is fired.
50 /* Format: 00:00:00.000000 plus NULL byte. */
53 extern DECLARE_URCU_TLS(struct log_time
, error_log_time
);
55 extern int lttng_opt_quiet
;
56 extern int lttng_opt_verbose
;
57 extern int lttng_opt_mi
;
61 #define PRINT_WARN 0x2
64 #define PRINT_DBG 0x10
65 #define PRINT_DBG2 0x20
66 #define PRINT_DBG3 0x30
69 * Macro for printing message depending on command line option and verbosity.
72 * We use lttng_opt_mi to suppress all normal msg to stdout. We don't
73 * want any nested msg to show up when printing mi to stdout(if it's the case).
74 * All warnings and errors should be printed to stderr as normal.
76 #define __lttng_print(type, fmt, args...) \
78 if (!lttng_opt_quiet&& !lttng_opt_mi && \
79 type == PRINT_MSG) { \
80 fprintf(stdout, fmt, ## args); \
81 } else if (!lttng_opt_quiet && !lttng_opt_mi && \
82 (((type & PRINT_DBG) && lttng_opt_verbose == 1) || \
83 ((type & (PRINT_DBG | PRINT_DBG2)) && \
84 lttng_opt_verbose == 2) || \
85 ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \
86 lttng_opt_verbose == 3))) { \
87 fprintf(stderr, fmt, ## args); \
88 } else if (!lttng_opt_quiet && \
89 (type & (PRINT_WARN | PRINT_ERR | PRINT_BUG))) { \
90 fprintf(stderr, fmt, ## args); \
94 /* Three level of debug. Use -v, -vv or -vvv for the levels */
95 #define _ERRMSG(msg, type, fmt, args...) __lttng_print(type, msg \
96 " - %s [%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
97 log_add_time(), (long) getpid(), (long) gettid(), ## args, __func__)
99 #define MSG(fmt, args...) \
100 __lttng_print(PRINT_MSG, fmt "\n", ## args)
101 #define _MSG(fmt, args...) \
102 __lttng_print(PRINT_MSG, fmt, ## args)
103 #define ERR(fmt, args...) \
104 __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
105 #define WARN(fmt, args...) \
106 __lttng_print(PRINT_ERR, "Warning: " fmt "\n", ## args)
108 #define BUG(fmt, args...) _ERRMSG("BUG", PRINT_BUG, fmt, ## args)
110 #define DBG(fmt, args...) _ERRMSG("DEBUG1", PRINT_DBG, fmt, ## args)
111 #define DBG2(fmt, args...) _ERRMSG("DEBUG2", PRINT_DBG2, fmt, ## args)
112 #define DBG3(fmt, args...) _ERRMSG("DEBUG3", PRINT_DBG3, fmt, ## args)
113 #define LOG(type, fmt, args...) \
120 WARN(fmt, ## args); \
132 DBG2(fmt, ## args); \
135 DBG3(fmt, ## args); \
142 #define _PERROR(fmt, args...) _ERRMSG("PERROR", PRINT_ERR, fmt, ## args)
144 #if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
147 * Version using XSI strerror_r.
149 #define PERROR(call, args...) \
152 strerror_r(errno, buf, sizeof(buf)); \
153 _PERROR(call ": %s", ## args, buf); \
157 * Version using GNU strerror_r, for linux with appropriate defines.
159 #define PERROR(call, args...) \
163 buf = strerror_r(errno, tmp, sizeof(tmp)); \
164 _PERROR(call ": %s", ## args, buf); \
168 const char *error_get_str(int32_t code
);
171 * Function that format the time and return the reference of log_time.str to
172 * the caller. On error, an empty string is returned thus no time will be
173 * printed in the log.
175 const char *log_add_time();
177 #endif /* _ERROR_H */
This page took 0.038459 seconds and 5 git commands to generate.