GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qoflog.h
1 /* qof-log.h
2  * Author: Rob Clark <[email protected]>
3  * Copyright (C) 1998-2003 Linas Vepstas <[email protected]>
4  * Copyright 2005 Neil Williams <[email protected]>
5  * Copyright 2007 Joshua Sled <[email protected]>
6  */
7 
8 /*
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301, USA
23  */
24 
84 #ifndef _QOF_LOG_H
85 #define _QOF_LOG_H
86 
87 #ifdef __cplusplus
88 extern "C"
89 {
90 #endif
91 
92 #include <stdarg.h>
93 #include <stdio.h>
94 #include <glib.h>
95 #include "qofutil.h"
96 
97 #define QOF_MOD_ENGINE "qof.engine"
98 
99 #define LOG_LEVEL_LIST(_) \
100  _(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR) \
101  _(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \
102  _(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \
103  _(QOF_LOG_MESSAGE, = G_LOG_LEVEL_MESSAGE) \
104  _(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \
105  _(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)
106 
107 DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST)
108 
109 const char* qof_log_level_to_string(QofLogLevel lvl);
110 QofLogLevel qof_log_level_from_string(const char *str);
111 
113 void qof_log_indent(void);
114 
118 void qof_log_dedent(void);
119 
124 void qof_log_init (void);
125 
127 void qof_log_set_level(QofLogModule module, QofLogLevel level);
128 
130 void qof_log_set_file (FILE *outfile);
131 
133 void qof_log_init_filename (const gchar* logfilename);
134 
140 void qof_log_init_filename_special(const char *log_to_filename);
141 
155 void qof_log_parse_log_config(const char *filename);
156 
158 void qof_log_shutdown (void);
159 
165 const gchar * qof_log_prettify (const gchar *name);
166 
169 gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level);
170 
172 void qof_log_set_default(QofLogLevel log_level);
173 
174 #define PRETTY_FUNC_NAME qof_log_prettify(G_STRFUNC)
175 
176 #ifdef _MSC_VER
177 /* Microsoft Visual Studio: MSVC compiler has a different syntax for
178  * macros with variadic argument list. */
179 
181 #define FATAL(format, ...) do { \
182  g_log (log_module, G_LOG_LEVEL_ERROR, \
183  "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
184 } while (0)
185 
187 #define PERR(format, ...) do { \
188  g_log (log_module, G_LOG_LEVEL_CRITICAL, \
189  "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
190 } while (0)
191 
193 #define PWARN(format, ...) do { \
194  g_log (log_module, G_LOG_LEVEL_WARNING, \
195  "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
196 } while (0)
197 
199 #define PINFO(format, ...) do { \
200  g_log (log_module, G_LOG_LEVEL_INFO, \
201  "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
202 } while (0)
203 
205 #define DEBUG(format, ...) do { \
206  g_log (log_module, G_LOG_LEVEL_DEBUG, \
207  "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
208 } while (0)
209 
211 #define ENTER(format, ...) do { \
212  if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \
213  g_log (log_module, G_LOG_LEVEL_DEBUG, \
214  "[enter %s:%s()] " format, __FILE__, \
215  PRETTY_FUNC_NAME , __VA_ARGS__); \
216  qof_log_indent(); \
217  } \
218 } while (0)
219 
221 #define LEAVE(format, ...) do { \
222  if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \
223  qof_log_dedent(); \
224  g_log (log_module, G_LOG_LEVEL_DEBUG, \
225  "[leave %s()] " format, \
226  PRETTY_FUNC_NAME , __VA_ARGS__); \
227  } \
228 } while (0)
229 
230 #else /* _MSC_VER */
233 #define FATAL(format, args...) do { \
234  g_log (log_module, G_LOG_LEVEL_ERROR, \
235  "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
236 } while (0)
239 #define PERR(format, args...) do { \
240  g_log (log_module, G_LOG_LEVEL_CRITICAL, \
241  "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
242 } while (0)
245 #define PWARN(format, args...) do { \
246  g_log (log_module, G_LOG_LEVEL_WARNING, \
247  "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
248 } while (0)
251 #define PINFO(format, args...) do { \
252  g_log (log_module, G_LOG_LEVEL_INFO, \
253  "[%s] " format, PRETTY_FUNC_NAME , ## args); \
254 } while (0)
257 #define DEBUG(format, args...) do { \
258  g_log (log_module, G_LOG_LEVEL_DEBUG, \
259  "[%s] " format, PRETTY_FUNC_NAME , ## args); \
260 } while (0)
263 #define ENTER(format, args...) do { \
264  if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \
265  g_log (log_module, G_LOG_LEVEL_DEBUG, \
266  "[enter %s:%s()] " format, __FILE__, \
267  PRETTY_FUNC_NAME , ## args); \
268  qof_log_indent(); \
269  } \
270 } while (0)
273 #define LEAVE(format, args...) do { \
274  if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \
275  qof_log_dedent(); \
276  g_log (log_module, G_LOG_LEVEL_DEBUG, \
277  "[leave %s()] " format, \
278  PRETTY_FUNC_NAME , ## args); \
279  } \
280 } while (0)
281 
282 #endif /* _MSC_VER */
285 #define gnc_leave_return_val_if_fail(test, val) do { \
286  if (! (test)) { LEAVE(""); } \
287  g_return_val_if_fail(test, val); \
288 } while (0);
291 #define gnc_leave_return_if_fail(test) do { \
292  if (! (test)) { LEAVE(""); } \
293  g_return_if_fail(test); \
294 } while (0);
295 
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif /* _QOF_LOG_H */
302 
void qof_log_set_level(QofLogModule module, QofLogLevel level)
void qof_log_dedent(void)
void qof_log_set_default(QofLogLevel log_level)
void qof_log_init(void)
void qof_log_shutdown(void)
void qof_log_init_filename_special(const char *log_to_filename)
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
const gchar * qof_log_prettify(const gchar *name)
void qof_log_init_filename(const gchar *logfilename)
void qof_log_indent(void)
QOF utility functions.
void qof_log_parse_log_config(const char *filename)
void qof_log_set_file(FILE *outfile)
const gchar * QofLogModule
Definition: qofid.h:89