733c9a139a4667fbcae6dac67cdc89426aa0c95c
[geeqie.git] / src / debug.h
1 /*
2  * Copyright (C) 2008 - 2016 The Geeqie Team
3  *
4  * Authors: Vladimir Nadvornik, Laurent Monin
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef _DEBUG_H
22 #define _DEBUG_H
23
24 #include <glib.h>
25
26 #define DOMAIN_DEBUG "debug"
27 #define DOMAIN_INFO  "info"
28
29 void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
30 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
31
32 #ifdef DEBUG
33
34 #define DEBUG_LEVEL_MIN 0
35 #define DEBUG_LEVEL_MAX 4
36
37 gint get_debug_level(void);
38 void set_debug_level(gint new_level);
39 void debug_level_add(gint delta);
40 gint required_debug_level(gint level);
41 const gchar *get_exec_time(void);
42 void init_exec_time(void);
43
44 #define DEBUG_N(n, ...) do \
45                                 { \
46                                 gint debug_level = get_debug_level(); \
47                                 if (debug_level >= (n))         \
48                                         {               \
49                                         if (debug_level != 1) log_domain_printf(DOMAIN_DEBUG, "%s:%d: ", __FILE__, __LINE__); \
50                                         log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \
51                                         log_domain_printf(DOMAIN_DEBUG, "\n"); \
52                                         } \
53                                 } while (0)
54
55 #else /* DEBUG */
56
57 #define get_debug_level() (0)
58 #define set_debug_level(new_level) do { } while(0)
59 #define debug_level_add(delta) do { } while(0)
60 #define required_debug_level(level) (0)
61 #define get_exec_time() ""
62 #define init_exec_time() do { } while(0)
63
64 #define DEBUG_N(n, ...)  do { } while(0)
65
66 #endif /* DEBUG */
67
68 #define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
69 #define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
70 #define DEBUG_2(...) DEBUG_N(2, __VA_ARGS__)
71 #define DEBUG_3(...) DEBUG_N(3, __VA_ARGS__)
72 #define DEBUG_4(...) DEBUG_N(4, __VA_ARGS__)
73
74
75 #endif /* _DEBUG_H */
76 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */