Cleanup main.h header
[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 #include <config.h>
27
28 #define DOMAIN_DEBUG "debug"
29 #define DOMAIN_INFO  "info"
30
31 void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
32 void log_domain_print_debug(const gchar *domain, const gchar *file_name, int line_number, const gchar *function_name, const gchar *format, ...) G_GNUC_PRINTF(5, 6);
33 void log_print_file_data_dump(const gchar *file, gint line_number, const gchar *function_name);
34 void log_print_backtrace(const gchar *file, gint line_number, const gchar *function_name);
35
36 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
37
38 #ifdef DEBUG
39
40 #define DEBUG_LEVEL_MIN 0
41 #define DEBUG_LEVEL_MAX 4
42
43 void set_regexp(const gchar *regexp);
44 gchar *get_regexp();
45 gint get_debug_level();
46 void set_debug_level(gint new_level);
47 void debug_level_add(gint delta);
48 gint required_debug_level(gint level);
49 const gchar *get_exec_time();
50 void init_exec_time();
51
52 #define DEBUG_N(n, ...) do \
53                                 { \
54                                 gint debug_level = get_debug_level(); \
55                                 if (debug_level >= (n))         \
56                                         {               \
57                                         if (debug_level != 1) \
58                                                 { \
59                                                 log_domain_print_debug(DOMAIN_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__);\
60                                                 } \
61                                         else \
62                                                 { \
63                                                 log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \
64                                                 } \
65                                         } \
66                                 } while (0)
67
68 /**
69  * @brief For use with the GTKInspector (>GTK 3.14)
70  *
71  * To simplify finding where objects are declared
72  * Sample command line call:
73  * GTK_DEBUG=interactive src/geeqie
74  */
75 #define DEBUG_NAME(widget) do \
76                                 { \
77                                 gtk_widget_set_name(GTK_WIDGET(widget), g_strdup_printf("%s:%d", __FILE__, __LINE__)); \
78                                 } while(0)
79
80 #define DEBUG_BT() do \
81                                 { \
82                                 log_print_backtrace(__FILE__, __LINE__, __func__);     \
83                                 } while(0)
84
85 #define DEBUG_FD() do \
86                                 { \
87                                 log_print_file_data_dump(__FILE__, __LINE__, __func__);\
88                                 } while(0)
89 #else /* DEBUG */
90
91 #define get_regexp() (0)
92 #define set_regexp(regexp) do { } while(0)
93 #define get_debug_level() (0)
94 #define set_debug_level(new_level) do { } while(0)
95 #define debug_level_add(delta) do { } while(0)
96 #define required_debug_level(level) (0)
97 #define get_exec_time() ""
98 #define init_exec_time() do { } while(0)
99
100 #define DEBUG_N(n, ...)  do { } while(0)
101
102 #define DEBUG_NAME(widget) do { } while(0)
103 #define DEBUG_BT() do { } while(0)
104 #define DEBUG_FD() do { } while(0)
105
106 #endif /* DEBUG */
107
108 #define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
109 #define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
110 #define DEBUG_2(...) DEBUG_N(2, __VA_ARGS__)
111 #define DEBUG_3(...) DEBUG_N(3, __VA_ARGS__)
112 #define DEBUG_4(...) DEBUG_N(4, __VA_ARGS__)
113
114
115 #endif /* _DEBUG_H */
116 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */