909f7e1aaab9034f988d3cdbc3805fc6ad9ab977
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.
26 #include <urcu/tls-compat.h>
30 #error "lttng-tools error.h needs _GNU_SOURCE"
33 #include <lttng/lttng-error.h>
34 #include <common/compat/tid.h>
36 /* Stringify the expansion of a define */
37 #define XSTR(d) STR(d)
41 * Contains the string of the log entry time. This is used as a thread local
42 * storage so we don't race between thread and also avoid memory allocation
43 * every time a log is fired.
46 /* Format: 00:00:00.000000 plus NULL byte. */
49 extern DECLARE_URCU_TLS(struct log_time
, error_log_time
);
51 extern int lttng_opt_quiet
;
52 extern int lttng_opt_verbose
;
53 extern int lttng_opt_mi
;
56 enum lttng_error_level
{
66 static inline bool __lttng_print_check_opt(enum lttng_error_level type
)
68 /* lttng_opt_mi and lttng_opt_quiet. */
81 if (lttng_opt_quiet
) {
86 /* lttng_opt_verbose */
89 if (lttng_opt_verbose
< 3) {
94 if (lttng_opt_verbose
< 2) {
99 if (lttng_opt_verbose
< 1) {
114 * Macro for printing message depending on command line option and verbosity.
117 * We use lttng_opt_mi to suppress all normal msg to stdout. We don't
118 * want any nested msg to show up when printing mi to stdout(if it's the case).
119 * All warnings and errors should be printed to stderr as normal.
121 #define __lttng_print(type, fmt, args...) \
123 if (__lttng_print_check_opt(type)) { \
124 fprintf((type) == PRINT_MSG ? stdout : stderr, fmt, ## args); \
128 /* Three level of debug. Use -v, -vv or -vvv for the levels */
129 #define _ERRMSG(msg, type, fmt, args...) __lttng_print(type, msg \
130 " - %s [%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
131 log_add_time(), (long) getpid(), (long) gettid(), ## args, __func__)
133 #define MSG(fmt, args...) \
134 __lttng_print(PRINT_MSG, fmt "\n", ## args)
135 #define _MSG(fmt, args...) \
136 __lttng_print(PRINT_MSG, fmt, ## args)
137 #define ERR(fmt, args...) \
138 __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
139 #define WARN(fmt, args...) \
140 __lttng_print(PRINT_WARN, "Warning: " fmt "\n", ## args)
142 #define BUG(fmt, args...) _ERRMSG("BUG", PRINT_BUG, fmt, ## args)
144 #define DBG(fmt, args...) _ERRMSG("DEBUG1", PRINT_DBG, fmt, ## args)
145 #define DBG2(fmt, args...) _ERRMSG("DEBUG2", PRINT_DBG2, fmt, ## args)
146 #define DBG3(fmt, args...) _ERRMSG("DEBUG3", PRINT_DBG3, fmt, ## args)
147 #define LOG(type, fmt, args...) \
154 WARN(fmt, ## args); \
166 DBG2(fmt, ## args); \
169 DBG3(fmt, ## args); \
176 #define _PERROR(fmt, args...) _ERRMSG("PERROR", PRINT_ERR, fmt, ## args)
178 #if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
181 * Version using XSI strerror_r.
183 #define PERROR(call, args...) \
186 strerror_r(errno, buf, sizeof(buf)); \
187 _PERROR(call ": %s", ## args, buf); \
191 * Version using GNU strerror_r, for linux with appropriate defines.
193 #define PERROR(call, args...) \
197 buf = strerror_r(errno, tmp, sizeof(tmp)); \
198 _PERROR(call ": %s", ## args, buf); \
202 const char *error_get_str(int32_t code
);
205 * Function that format the time and return the reference of log_time.str to
206 * the caller. On error, an empty string is returned thus no time will be
207 * printed in the log.
209 const char *log_add_time();
211 #endif /* _ERROR_H */
This page took 0.032795 seconds and 3 git commands to generate.