Initial import
[lttng-tools.git] / include / lttngerr.h
1 /* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 */
18
19 #ifndef _LTTNGERR_H
20 #define _LTTNGERR_H
21
22 #include <errno.h>
23 #include <stdarg.h>
24
25 extern int opt_quiet;
26 extern int opt_verbose;
27
28 enum __lttng_print_type {
29 PRINT_ERR,
30 PRINT_WARN,
31 PRINT_BUG,
32 PRINT_DBG,
33 PRINT_MSG,
34 };
35
36 /*
37 * __lttng_print
38 *
39 * Internal function for printing message
40 * depending on command line option and verbosity.
41 */
42 void __lttng_print(enum __lttng_print_type type, const char *fmt, ...)
43 {
44 va_list ap;
45 va_start(ap, fmt);
46
47 if (opt_quiet == 0) {
48 if (type == PRINT_MSG || (opt_verbose && type == PRINT_DBG)) {
49 vfprintf(stdout, fmt, ap);
50 } else if (type != PRINT_MSG && type != PRINT_DBG) {
51 vfprintf(stderr, fmt, ap);
52 }
53 }
54
55 va_end(ap);
56 }
57
58 #define MSG(fmt, args...) __lttng_print(PRINT_MSG, fmt "\n", ## args)
59 #define ERR(fmt, args...) __lttng_print(PRINT_ERR, "Error: " fmt "\n", ## args)
60 #define WARN(fmt, args...) __lttng_print(PRINT_WARN, "Warning: " fmt "\n", ## args)
61 #define BUG(fmt, args...) __lttng_print(PRINT_BUG, "BUG: " fmt "\n", ## args)
62 #define DBG(fmt, args...) __lttng_print(PRINT_DBG, "DEBUG: " fmt "\n", ## args)
63
64 #endif /* _LTTNGERR_H */
This page took 0.043205 seconds and 4 git commands to generate.