Do not use printf() directly but use new wrapper function log_printf() instead.
[geeqie.git] / src / debug.h
1 /*
2  * Geeqie
3  * Copyright (C) 2008 The Geeqie Team
4  *
5  * Authors: Vladimir Nadvornik, Laurent Monin
6  *
7  * This software is released under the GNU General Public License (GNU GPL).
8  * Please read the included file COPYING for more information.
9  * This software comes with no warranty of any kind, use at your own risk!
10  */
11
12 #ifndef DEBUG_H
13 #define DEBUG_H
14
15 #define DOMAIN_DEBUG "debug"
16 #define DOMAIN_INFO  "info"
17
18 gint log_domain_printf(const char *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
19 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
20
21
22
23
24 #if 1 /* set to 0 to disable compilation of debugging code and related options */
25 # ifndef DEBUG
26 # define DEBUG 1
27 # endif
28 #endif
29
30 #ifdef DEBUG
31
32 #define DEBUG_LEVEL_MIN 0
33 #define DEBUG_LEVEL_MAX 4
34
35 gint get_debug_level(void);
36 void set_debug_level(gint new_level);
37 void debug_level_add(gint delta);
38 gint required_debug_level(gint level);
39 const gchar *get_exec_time(void);
40 void init_exec_time(void);
41
42 #define DEBUG_N(n, ...) do \
43                                 { \
44                                 gint debug_level = get_debug_level(); \
45                                 if (debug_level >= (n))         \
46                                         {               \
47                                         if (debug_level != 1) log_domain_printf(DOMAIN_DEBUG, "%s:%d: ", __FILE__, __LINE__); \
48                                         log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \
49                                         log_domain_printf(DOMAIN_DEBUG, "\n"); \
50                                         } \
51                                 } while (0)
52
53 #else /* DEBUG */
54
55 #define get_debug_level() (0)
56 #define set_debug_level(new_level) do { } while(0)
57 #define debug_level_add(delta) do { } while(0)
58 #define required_debug_level(level) (0)
59 #define get_exec_time() ""
60 #define init_exec_time() do { } while(0)
61
62 #define DEBUG_N(n, ...)  do { } while(0)
63
64 #endif /* DEBUG */
65
66 #define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
67 #define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
68 #define DEBUG_2(...) DEBUG_N(2, __VA_ARGS__)
69 #define DEBUG_3(...) DEBUG_N(3, __VA_ARGS__)
70 #define DEBUG_4(...) DEBUG_N(4, __VA_ARGS__)
71
72
73 #endif /* DEBUG_H */