2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
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 with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
26 #error "lttng-tools error.h needs _GNU_SOURCE"
29 /* Stringify the expansion of a define */
30 #define XSTR(d) STR(d)
34 extern int opt_verbose
;
37 #define PRINT_WARN 0x2
40 #define PRINT_DBG 0x10
41 #define PRINT_DBG2 0x20
42 #define PRINT_DBG3 0x30
45 * Macro for printing message depending on command line option and verbosity.
47 #define __lttng_print(type, fmt, args...) \
49 if (opt_quiet == 0 && type == PRINT_MSG) { \
50 fprintf(stdout, fmt, ## args); \
51 } else if (opt_quiet == 0 && \
52 (((type & PRINT_DBG) && opt_verbose == 1) || \
53 ((type & (PRINT_DBG | PRINT_DBG2)) && \
54 opt_verbose == 2) || \
55 ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \
56 opt_verbose == 3))) { \
57 fprintf(stderr, fmt, ## args); \
58 } else if (opt_quiet == 0 && (type & (PRINT_WARN))) { \
59 fprintf(stderr, fmt, ## args); \
60 } else if (type & (PRINT_ERR | PRINT_BUG)) { \
61 fprintf(stderr, fmt, ## args); \
65 #define MSG(fmt, args...) \
66 __lttng_print(PRINT_MSG, fmt "\n", ## args)
67 #define ERR(fmt, args...) \
68 __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
69 #define WARN(fmt, args...) \
70 __lttng_print(PRINT_WARN, "Warning: " fmt "\n", ## args)
71 #define BUG(fmt, args...) \
72 __lttng_print(PRINT_BUG, "BUG: " fmt "\n", ## args)
74 /* Three level of debug. Use -v, -vv or -vvv for the levels */
75 #define DBG(fmt, args...) __lttng_print(PRINT_DBG, "DEBUG1: " fmt \
76 " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
77 #define DBG2(fmt, args...) __lttng_print(PRINT_DBG2, "DEBUG2: " fmt \
78 " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
79 #define DBG3(fmt, args...) __lttng_print(PRINT_DBG3, "DEBUG3: " fmt \
80 " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
82 #define _PERROR(fmt, args...) \
83 __lttng_print(PRINT_ERR, "PERROR: " fmt \
84 " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
86 #define PERROR(call, args...) \
90 buf = strerror_r(errno, tmp, sizeof(tmp)); \
91 _PERROR(call ": %s", ## args, buf); \
This page took 0.030865 seconds and 4 git commands to generate.